title: Waiting DownloadFileAsync with ManualResetEvent c++/cli
body: <p>i'm having a little but frustrating problem in my C++/CLI with windows forms application.</p>
  
  <p>So the problem is that i have to download a file from a webserver by using a WebClient istance. Normally i use DownloadFile and not DownoadFileAsyn, but if i want to show a progress bar showing the progress of download file, i MUST use DownloadFileAsyn. So how can i wait the process of downloading until it's finished ?</p>
  
  <p>The code is:</p>
  
  <pre><code>    ref class Example{
  
      private:
  
          static System::Threading::ManualResetEvent^ mre = gcnew System::Threading::ManualResetEvent(false);
  
      public:
  
          void Download();
          void DownloadFileCompleted(Object^ sender, System::ComponentModel::AsyncCompletedEventArgs^ e);
      };
  
  
  
  
  
  
  void Example::Download(){
  
      WebClient^ request = gcnew WebClient;
      request-&gt;Credentials = gcnew NetworkCredential("anonymous", "anonymous");
  
      request-&gt;DownloadFileCompleted += gcnew System::ComponentModel::AsyncCompletedEventHandler(this,&amp;FileCrypt::DownloadFileCompleted);
  
      request-&gt;DownloadFileAsync(gcnew Uri("ftp://ftp...."+remote_path),remote_file,mre);
      mre-&gt;WaitOne();
  
  
  /*
  BLOCK OF INSTRUCTIONS THAT I WANT TO RUN AFTER THE FILE DOWNLOAD IS COMPLETED
  
  */
  }
  
  void Example::DownloadFileCompleted(Object^ sender, System::ComponentModel::AsyncCompletedEventArgs^ e){
      MessageBox::Show("COMPLETED");
      mre-&gt;Set();
  }
  </code></pre>
  
  <p>So when the download is completed, the program stop running and it doesn't run the block of instructions above written, after the mre->WaitOne() instruction.
  The DownloadFileCompleted() is not executed, in fact even the messagebox is shown. </p>
  
  <p>Any ideas? I've serarched for this problem, and many people had it, but in c# only. And i've just "translated" the solution from c# to c++. But it doesn't work...</p>