Saturday, 15 September 2012

c# - Copy same file from multiple threads to multiple destinations -


I am trying to write an application that made copies and installers in the list of computers I provided. It works perfectly with only one computer name in the input, but when I add two or more, it tells me that it can not be read from the source file because it is in use.

Update: I'm open to other ways to get it done if it's just a lost cause my ultimate goal is only the possible copying of files as soon as possible, which is over 500 computers in the same datacenter There will be a copy. Then execute the file on all those computers, for execution now, I am using psexec -s so I can bypass UAC. Click the code below

  / * button * / / * Install specific OS * / foreach (string line in txtservers). Lines) {machine = line; LbOutput.Items.Add ("Preparing to Copy File ..."); / * Copy files * / if (! TWorker.IsAlive) tWorker.Start (); LbOutput.Items.Add ("complete copy file! Installer installer ...."); } / * The file copy code * / try {file.Copy ( "Ionic.Zip.Reduced.dll", @ "\\" + + machine + @ "\ C $ \ Temp \ Ionic.Zip.Reduced.dll ", truth ); File. Copy ("v5.32bit.Install.exe", @ "\\" + Machine + @ "\ C $ \ Temp \ v5.32bit.Install.exe", true); } Hold (exception EE) {message box. Show (E.M. message); }    

Another way to go is to cache files in memory ....

Load something like

  var files = new [] {"a.txt", "b.txt"}. ToList (); Var file = new dictionary & lt; String, byte [] & gt; ();   

Then when you want to write them

    files Toolist (.). First (F = & gt; File. WritAllBytes (Path.Combine (MachinePath, F), Files [F]));    

No comments:

Post a Comment