C# How copy multiple files in multiple thread to speed up the copy process

Sudip Bhatt 2,281 Reputation points
2021-01-11T17:17:16.153+00:00

I heard that if i use multiple thread to copy multiple files from one pc to another pc it does not speed up. tell me which approach i should follow to copy files parallel which would be faster in speed?

should i use RoboCopy ? i heard i am not sure RoboCopy can help to copy multiples files from pc to another pc very faster. so please advise.
i found there is .Net wrapper of RoboCopy called RoboSharp https://github.com/tjscience/RoboSharp
should i use it ?

should i follow this approach https://forums.asp.net/t/1552575.aspx?Copy+file+s+from+source+folder+to+destination+using+Multi+Threading

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Timon Yang-MSFT 9,606 Reputation points
    2021-01-12T07:15:14.627+00:00

    If you just want to use RoboCopy in your code, the following code should be enough:

      private static void DirectoryCopy1(string sourceDirName, string destDirName,string fileName)  
            {  
                using (Process p = new Process())  
                {  
                    p.StartInfo.Arguments = string.Format("/C ROBOCOPY {0} {1} {2}",  
                            sourceDirName, destDirName, fileName);  
                    p.StartInfo.FileName = "CMD.EXE";  
                    p.StartInfo.UseShellExecute = false;  
                    p.Start();  
                }  
            }  
    

    If you want to copy the entire folder and all subfolders, the third parameter can be passed "/e".
    I used this method to compare with the method in the second link you provided, but the speed of the two methods is almost the same.
    However, I still recommend that you use RoboCopy. In the actual copying process, we may have to consider many factors.
    RoboCopy provides solutions for many situations, such as "/z", which means that restartable mode is enabled, which can restart after copying fails. This may be useful during network transmission.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. cheong00 3,486 Reputation points Volunteer Moderator
    2021-01-12T08:18:02.42+00:00

    Copy with multiple thread won't make you do it faster.

    Even the old SATA standard can transfer data faster(150MB/s, with SATA III you can get up to 600MB/s) than your Gigabit network(theoretical limit at about 123MB/s, and this assumes your source and destination machines are the only thing on network so no other network activity consumes your bandwidth). The bottleneck is on the network, not I/O to disks.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.