title: TaskCompletionSource throws "An attempt was made to transition a task to a final state when it had already completed"
body: <p>I want to use <code>TaskCompletionSource</code> to wrap <code>MyService</code> which is a simple service:</p>
  
  <pre><code>public static Task&lt;string&gt; ProcessAsync(MyService service, int parameter)
  {
      var tcs = new TaskCompletionSource&lt;string&gt;();
      //Every time ProccessAsync is called this assigns to Completed!
      service.Completed += (sender, e)=&gt;{ tcs.SetResult(e.Result); };   
      service.RunAsync(parameter);
      return tcs.Task;
  }
  </code></pre>
  
  <p>This code is working well for the first time. But the <strong>second</strong> time I call <code>ProcessAsync</code> simply the event handler for the <code>Completed</code> is assign again (the same <code>service</code> variable is used every time) and thus it will execute twice! and the second time it throws this exception:</p>
  
  <blockquote>
    <p>attempt transition task final state when already completed</p>
  </blockquote>
  
  <p>I'm not sure, should I declare the <code>tcs</code> as a class level variable like this:</p>
  
  <pre><code>TaskCompletionSource&lt;string&gt; tcs;
  
  public static Task&lt;string&gt; ProccessAsync(MyService service, int parameter)
  {
      tcs = new TaskCompletionSource&lt;string&gt;();
      service.Completed -= completedHandler; 
      service.Completed += completedHandler;
      return tcs.Task;    
  }
  
  private void completedHandler(object sender, CustomEventArg e)
  {
      tcs.SetResult(e.Result); 
  }
  </code></pre>
  
  <p>I have to wrap many methods with different return types and this way I have to write lost of code, variables, event handlers so I'm not sure if this is the best practice in this scenarios. So is there any better way of doing this job?</p>