title: How to use Task<T> raising an event and waiting for event to be finished
body: <p>I have the following scenario:</p>
  
  <ol>
  <li><p>Client who is requesting a webservice to start </p>
  
  <pre><code>public bool Start(MyProject project, string error)
  </code></pre></li>
  <li><p>A web service who receives the call from the client in a method</p>
  
  <pre><code>public event EventHandler&lt;StartEventArgs&gt; startEvent;
  
  public bool Start(MyProject project, string error)
  {
      Task&lt;bool&gt; result = StartAsync(project, error);
  
      return result.Result;
  }
  
  protected virtual void OnStart(StartEventArgs e)
  {
      // thread safe trick, snapshot of event
      var se = startEvent;
      if (se != null)
      {
          startEvent(this, e);
      }
  }
  
  private Task&lt;bool&gt; StartAsync(MyProject project, string error)
  {
      var taskCompletion = new TaskCompletionSource&lt;bool&gt;();
  
      this.startEvent += (p, e) =&gt; taskCompletion.TrySetResult((e.Error == string.Empty) ? true : false);
  
      this.OnStart(new StartEventArgs(project, error));
  
      return taskCompletion.Task;
  }
  </code></pre></li>
  <li><p>An application that is subscribing to an event that is located in the web service:</p>
  
  <pre><code>app.Start += EventHandler(App_Start)
  
  private bool App_Start()
  {
     // does something
     returns true/false
  }
  </code></pre></li>
  <li><p>I want the web service to fire off the event in a Task, then wait for the function in the app.exe to finish and then return here to notify the user that the task has completed successfully.</p></li>
  </ol>
  
  <p>I am not sure how to do this but in theory it would look something like this:</p>
  
  <pre><code>Task&lt;bool&gt; startTask = Task.Factory.StartNew(() =&gt; { OnStart() });
  startTask.WaitAll(); // I think this is what I would need to for 4.0
  return startTask.Result
  </code></pre>
  
  <p>I hope I am being descriptive enough for someone to see what I am trying to do. I would like the service to not have to know anything about the client and just run the task and once the event has finished its execution come back to this point and return to client a Boolean value representing success/failure.</p>
  
  <p>Is this possible or am I taking a really wrong approach with this?</p>
  
  <p><strong>Update:</strong>
  Obviously OnStart is not an event so how do I do what you are trying to explain to me?</p>