title: How do I wait for a C# event to be raised?
body: <p>I have a <code>Sender</code> class that sends a <code>Message</code> on a <code>IChannel</code>:</p>
  
  <pre><code>public class MessageEventArgs : EventArgs {
    public Message Message { get; private set; }
    public MessageEventArgs(Message m) { Message = m; }
  }
  
  public interface IChannel {
    public event EventHandler&lt;MessageEventArgs&gt; MessageReceived;
    void Send(Message m);
  }
  
  public class Sender {
    public const int MaxWaitInMs = 5000;
    private IChannel _c = ...;
  
    public Message Send(Message m) {
      _c.Send(m);
      // wait for MaxWaitInMs to get an event from _c.MessageReceived
      // return the message or null if no message was received in response
    }
  }
  </code></pre>
  
  <p>When we send messages, the <code>IChannel</code> sometimes gives a response depending on what kind of <code>Message</code> was sent by raising the <code>MessageReceived</code> event. The event arguments contain the message of interest.</p>
  
  <p>I want <code>Sender.Send()</code> method to wait for a short time to see if this event is raised. If so, I'll return its <code>MessageEventArgs.Message</code> property. If not, I return a null <code>Message</code>.</p>
  
  <p>How can I wait in this way? I'd prefer not to have do the threading legwork with <code>ManualResetEvents</code> and such, so sticking to regular <code>event</code>s would be optimal for me.</p>