title: C# : Blocking a function call until condition met
body: <p>I am developing a C# Winforms application, part of the application will be uploading files to a webserver using AsyncUpload (using it,due to the need to use a porgress callback) , In the C# program </p>
  
  <p>i got a simple for loop that calls The Uploading function</p>
  
  <pre><code> for(int i=0;i &lt; 10 ; i++)
  {
    Uploadfun();
  }
  </code></pre>
  
  <p>And the fun does some magic:</p>
  
  <pre><code>Uploadfun()
    { 
    // Logic comes here
  
     // webClient.UploadFileAsync runs a 2nd thread to perform upload .. 
     webClient.UploadFileAsync(uri, "PUT", fileNameOnHD);  
  
   }
  </code></pre>
  
  <p>And a callback that gets called when the Async upload is done</p>
  
  <pre><code>Upload_Completed_callback()
  {
    //Callback event
  }
  </code></pre>
  
  <p><b>Edit</b></p>
  
  <p>The logic sequence: </p>
  
  <ol>
  <li>Fun gets called (from loop)</li>
  <li>Fun logic is executed and done..</li>
  <li>Goes back to for loop </li>
  <li>Callback will be called eventually, when UploadFileAsync (which is running some logic in another thread) will end</li>
  </ol>
  
  <p>The problem is on the 3rd point, when the execution moves back to the for loop, i need to block the loop from continuing until the callback get called.</p>