title: Copy Multiple Files in a Thread
body: <p>I've the following scenario, I've to copy multiple (about 10,50,200,...) files. I do that syncronously one after another. This is my code snippet for that.</p>
  
  <pre><code>static void Main(string[] args)
          {
              string path = @"";
              FileSystemWatcher listener = new FileSystemWatcher(path);
              listener.Created += new FileSystemEventHandler(listener_Created);
              listener.EnableRaisingEvents = true;
  
              while (Console.ReadLine() != "exit") ;
          }
  
          public static void listener_Created(object sender, FileSystemEventArgs e)
          {
              while (!IsFileReady(e.FullPath)) ;
              File.Copy(e.FullPath, @"D:\levani\FolderListenerTest\CopiedFilesFolder\" + e.Name);
          }
  </code></pre>
  
  <p>So when files are created in some folder and it's ready to use I copy that file one after another, but I need to start copying as soon as any file is ready to use. So I think I should use Threads. So.. <strong>How to implement parallel copying?</strong></p>
  
  <p>@Chris</p>
  
  <p><strong>Check if file is ready</strong></p>
  
  <pre><code>public static bool IsFileReady(String sFilename)
          {
              // If the file can be opened for exclusive access it means that the file
              // is no longer locked by another process.
              try
              {
                  using (FileStream inputStream = File.Open(sFilename, FileMode.Open, FileAccess.Read, FileShare.None))
                  {
                      if (inputStream.Length &gt; 0)
                      {
                          return true;
                      }
                      else
                      {
                          return false;
                      }
  
                  }
              }
              catch (Exception)
              {
                  return false;
              }
          }
  </code></pre>