title: Async result handle to return to callers
body: <p>I have a method that queues some work to be executed asynchronously. I'd like to return some sort of handle to the caller that can be polled, waited on, or used to fetch the return value from the operation, but I can't find a class or interface that's suitable for the task.</p>
  
  <p>BackgroundWorker comes close, but it's geared to the case where the worker has its own dedicated thread, which isn't true in my case. IAsyncResult looks promising, but the provided AsyncResult implementation is also unusable for me. Should I implement IAsyncResult myself?</p>
  
  <p><strong>Clarification</strong>:</p>
  
  <p>I have a class that conceptually looks like this:</p>
  
  <pre><code>class AsyncScheduler 
  {
  
      private List&lt;object&gt; _workList = new List&lt;object&gt;();
      private bool _finished = false;
  
      public SomeHandle QueueAsyncWork(object workObject)
      {
          // simplified for the sake of example
          _workList.Add(workObject);
          return SomeHandle;
      }
  
      private void WorkThread()
      {
          // simplified for the sake of example
          while (!_finished)
          {
              foreach (object workObject in _workList)
              {
                  if (!workObject.IsFinished)
                  {
                      workObject.DoSomeWork();
                  }
              }
              Thread.Sleep(1000);
          }
      }
  }
  </code></pre>
  
  <p>The QueueAsyncWork function pushes a work item onto the polling list for a dedicated work thread, of which there will only over be one. My problem is not with writing the QueueAsyncWork function--that's fine. My question is, what do I return to the caller? What should <code>SomeHandle</code> be? </p>
  
  <p>The existing .Net classes for this are geared towards the situation where the asynchronous operation can be encapsulated in a single method call that returns. That's not the case here--all of the work objects do their work on the same thread, and a complete work operation might span multiple calls to <code>workObject.DoSomeWork()</code>. In this case, what's a reasonable approach for offering the caller some handle for progress notification, completion, and getting the final outcome of the operation?</p>