Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Interesting problem. I came up with two approaches. The first is based on PLinq and the second is based on te Rx Framework.</p> <p>The first one iterates through the files in parallel. The second one generates asynchronously the files from the directory.</p> <p>Here is how it looks like in a much simplified version (The first method does require .Net 4.0 since it uses PLinq)</p> <pre><code>string direcory = "Mydirectory"; var jpegFiles = System.IO.Directory.EnumerateFiles(direcory,"*.jpg"); // -- PLinq -------------------------------------------- jpegFiles .AsParallel() .Select(imageFile =&gt; new {OldLocation = imageFile, NewLocation = GenerateCopyLocation(imageFile) }) .Do(fileInfo =&gt; { if (!File.Exists(fileInfo.NewLocation ) || (File.GetCreationTime(fileInfo.NewLocation)) != (File.GetCreationTime(fileInfo.NewLocation))) File.Copy(fileInfo.OldLocation,fileInfo.NewLocation); }) .Run(); // ----------------------------------------------------- //-- Rx Framework --------------------------------------------- var resetEvent = new AutoResetEvent(false); var doTheWork = jpegFiles.ToObservable() .Select(imageFile =&gt; new {OldLocation = imageFile, NewLocation = GenerateCopyLocation(imageFile) }) .Subscribe( fileInfo =&gt; { if (!File.Exists(fileInfo.NewLocation ) || (File.GetCreationTime(fileInfo.NewLocation)) != (File.GetCreationTime(fileInfo.NewLocation))) File.Copy(fileInfo.OldLocation,fileInfo.NewLocation); },() =&gt; resetEvent.Set()); resetEvent.WaitOne(); doTheWork.Dispose(); // ----------------------------------------------------- </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload