How to implement a performant filecopy method in C# from a network share? How to implement a performant filecopy method in C# from a network share? windows windows

How to implement a performant filecopy method in C# from a network share?


Try changing the buffer size to equal the sector size on the hard disk - likely 4Kb. Also use the System.Diagnostics.Stopwatch class for timing.

I also wouldn't bother using the async methods in a tight loop - it will incur some overhead going away and allocating a thread from the pool to do the work.

Again also, make use of the using statement for managing the disposal of your streams. Note however that this will skew your timing as you are currently disposing the objects after stopping the timer.


Did you try smaller buffer sizes? A buffer size of 1mb is awfully huge and normally buffer sizes of 4-64kb give you best performance.

Also, this may be related to your question: How to write super-fast file-streaming code in C#?

And maybe you can improve performance using memory mapped files: http://weblogs.asp.net/gunnarpeipman/archive/2009/06/21/net-framework-4-0-using-memory-mapped-files.aspx


There are the usual suspects for increasing speed over a network:

  • Have multiple download threads
  • Pre-allocate the block on the disk where the file will reside

Other than that, you're at the mercy of your hardware limitations.