title: Block while waiting for event
body: <p>I have an external COM-object that connects to a server and then fire an event when the server is ready. The connect() call is thus asynchronously.</p>
  
  <p>My code looks (a bit...) like</p>
  
  <pre><code>ManualResetEvent waitConnection;
  
  //This is the event that is triggered when server is ready
  public void onConnection_event(bool success)
  {
      if(success)
          waitConnection.Set();
  }
  
  private string getItem(string itemName)
  {
      //MYDBCom is a win32 com if that makes any difference
      MYDBCom myDBobject = new MYDBCom();
      waitConnection = new ManualResetEvent(false);
      myDBobject.connect();              //asynchron call.
  
      //wait until server triggers the onConnection_event
      waitConnection.WaitOne();
      //server is now ready. Get the data from the server.
      return myDBobject.getItem(itemName);
  }
  </code></pre>
  
  <p>The problem is that the event is not triggered - it seems to be blocked while waiting in WaitOne. If I instead of using waitOne use</p>
  
  <pre><code>    while(!connected)
      {
          Sleep(100);
          DoEvents();
      }
  </code></pre>
  
  <p>the event is triggered.</p>
  
  <p>Any ideas why WaitOne blocks? Are there any other suggestions how to wait until an event triggers?</p>
  
  <p>//Fredrik</p>