title: Wait for previous function to complete
body: <p>I'm working on a web installer and one of the things I have currently is</p>
  
  <pre><code>    void MoveFiles()
      {
          lbldlstatus.Text = "Moving Files";
          string InstallDirectory = Directory.GetCurrentDirectory() + "/DoxramosRepack-master";
          DirectoryInfo d = new DirectoryInfo(InstallDirectory);
          foreach(var file in d.GetFiles("*"))
          {
              try
              {
                  if (File.Exists(file.Name)) {
                  File.Delete(file.Name);
              }
  
                  Directory.Move(file.FullName, file.Name);
                  Cleanup();
              }
              catch(Exception e)
              {
                  MessageBox.Show(e.ToString());
                  lbldlstatus.Text = "Repack Installation Failed";
              }
          }            
      }
      void Cleanup()
      {
          lbldlstatus.Text = "Cleaning Up Files";
          try
          {
              if (File.Exists("Repack.zip"))
              {
                  File.Delete("Repack.zip");
              }
              if(Directory.Exists("DoxramosRepack-master"))
              {
                  Directory.Delete("DoxramosRepack-master");
              }
              lbldlstatus.Text = "Repack Installed Successfully";
          }
  </code></pre>
  
  <p>When I get to <code>Cleanup()</code> I have a <code>System.IO.IOException</code>. </p>
  
  <blockquote>
    <p>Process cannot access the file Repack.zip because it being used by
    another process.</p>
  </blockquote>
  
  <p>The full code runs </p>
  
  <p>Download->Extract->Move->Cleanup. </p>
  
  <p>I'm not sure what process is being used, but I'm looking to find a way for each process to wait for the previous to finish before starting. </p>