title: Cancelling tasks in the Dispose method
body: <p>I have a class which spawns various tasks which can run indefinitely.  When this object is disposed, I want to stop those tasks from running.  </p>
  
  <p>Is this the correct approach:</p>
  
  <pre><code>public class MyClass : IDisposable
  {
      // Stuff
  
      public void Dispose()
      {
          Dispose(true);
          GC.SuppressFinalize(this);
      }
  
      protected virtual void Dispose(bool disposing)
      {
          if (disposing)
          {
              queueCancellationTokenSource.Cancel();
              feedCancellationTokenSource.Cancel();
          }
      }
  }
  </code></pre>