You are on the right track. However, I suggest waiting for the task to complete before returning from the Dispose method to avoid race conditions when the task continues to work after the object has been deleted. Also post a CancellationTokenSource .
public class MyClass : IDisposable { private readonly CancellationTokenSource feedCancellationTokenSource = new CancellationTokenSource(); private readonly Task feedTask; public MyClass() { feedTask = Task.Factory.StartNew(() => { while (!feedCancellationTokenSource.IsCancellationRequested) {
Douglas
source share