Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. var task1 = Task.Factory.StartNew(() =>
  2. {
  3. File.Copy(Path,NewName1, true);
  4. });
  5. var task2 = Task.Factory.StartNew(() =>
  6. {
  7. File.Copy(Path,NewName2, true);
  8. });
  9.  
  10. public void ParallelCopy(string src, params string[] dsts)
  11. {
  12. Parallel.ForEach(dsts, new ParallelOptions(),
  13. dstOne =>
  14. {
  15. using (FileStream source = new FileStream(src, FileMode.Open, FileAccess.Read, FileShare.Read))
  16.  
  17. using (FileStream destination = new FileStream(dstOne, FileMode.Create))
  18. {
  19. var buffer = new byte[4096];
  20. int read;
  21.  
  22. while ((read = source.Read(buffer, 0, buffer.Length)) > 0)
  23. {
  24. destination.Write(buffer, 0, read);
  25. }
  26. }
  27.  
  28. });
  29. }
  30.  
  31. ParallelCopy(@"x:source.file", @"c:destination1.file", @"d:destination2.file");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement