title: How I can change the event as a different method in c#
body: <p>I need to separate my event as a different method.. But I am using TaskCompletionSource and don't know how can i do that?</p>
  
  <p>Here is my code </p>
  
  <pre><code>    public Task&lt;byte[]&gt; Download(DocumentProfile profile)
      {
  
          var tcs = new TaskCompletionSource&lt;byte[]&gt;();
  
  
          service.DownloadLastVersionCompleted += (sender, args) =&gt;
          {
                  if (args.Error != null)
                      tcs.TrySetResult(null);
                  if (args.Result != null)
                      tcs.TrySetResult(args.Result);
                  else
                      tcs.TrySetResult(new byte[0]);
  
              };
  
          service.DownloadLastVersionAsync(profile);
          return tcs.Task;
      }
  </code></pre>
  
  <p>and I want to do like this</p>
  
  <pre><code>public Task&lt;byte[]&gt; Download(DocumentProfile profile)
  {
       var tcs = new TaskCompletionSource&lt;byte[]&gt;();
  
  
       service.DownloadLastVersionCompleted+=OnDownloadCompleted;
       service.DownloadLastVersionAsync(profile);
  
       return tcs.Task;
  }
  
  
  private void OnDownloadCompleted(object sender, DownloadLastVersionCompletedEventArgs e)
  {
      .....
  }
  </code></pre>
  
  <p>but here is the problem, how i can return task with that kind of different method. Sometimes I have exception because when I downloaded because of this kind of event, as I search, recommended to separate this event.. </p>
  
  <p>I hope its clear..</p>