title: C#: Downloading a video file (MP4) results in WebException
body: <p>During various downloads, I seem to be getting a "file is already used by another process." when downloading the file at <code>webClient.DownloadFile</code> line.</p>
  
  <p>This file hasn't been downloaded before, so how can it be open elsewhere? It seems to only happen when I'm downloading files of type MP4, which is strange.</p>
  
  <p>Exception:</p>
  
  <blockquote>
    <p>System.Net.WebException: An exception occurred during a WebClient
    request. ---> System.IO.IOException: The process cannot access the
    file 'M:\blah\blah\blah' because it is being used by another process.</p>
  </blockquote>
  
  <p>Code:</p>
  
  <pre><code>public static class DownloadUtilities
  {
      public static int FailedDownloadCount;
  
      public static void DownloadLinks(List&lt;AFile&gt; files)
      {
          FailedDownloadCount = 0;
  
          Parallel.ForEach(
              files,
              new ParallelOptions { MaxDegreeOfParallelism = 20 },
              currentFile =&gt; { DownloadFile(currentFile); }
          );
      }
  
      private static void DownloadFile(AFile file)
      {
          try
          {
              using (var webClient = new WebClient())
              {
                  webClient.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0)");
                  webClient.DownloadFile(new Uri(file.Address), file.SaveLocation);
              }
          }
          catch (WebException e)
          {
              Logger.Warn(e.ToString());
          }
  
          System.Threading.Thread.Sleep(250);
      }
  }
  </code></pre>