File.Copy vs. Manual FileStream.Write For Copying File

后端 未结 8 1893
悲&欢浪女
悲&欢浪女 2020-11-27 04:41

My problem is in regards file copying performance. We have a media management system that requires a lot of moving files around on the file system to different locations inc

8条回答
  •  日久生厌
    2020-11-27 05:21

    One thing that stands out is that you are reading a chunk, writing that chunk, reading another chunk and so on.

    Streaming operations are great candidates for multithreading. My guess is that File.Copy implements multithreading.

    Try reading in one thread and writing in another thread. You will need to coordinate the threads so that the write thread doesn't start writing away a buffer until the read thread is done filling it up. You can solve this by having two buffers, one that is being read while the other is being written, and a flag that says which buffer is currently being used for which purpose.

提交回复
热议问题