Take the 2-minute tour ×

I have several long-running Task objects. I'd like them all to just keep running indefinitely. The job of one of these tasks is to self-monitor the system. If something happens outside of normal operating conditions, I'd like it to be able to stop running and somehow signal the other tasks to stop running as well. Is it enough to just use Task.WaitAny(), stop the one thread and the others will stop, or will those other Tasks keep running indefinitely?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Those Tasks will continue running, unless you explicitly handle cancellation.

The preferred method to handle this is using the new cooperative cancellation support in .NET 4.

The normal method would be to have a continuation on each task that runs when a task fails/faults. It could then have a CancelationTokenSource that gets canceled. Each task can occasionally check to see if it should abort because a cancellation is requested.

share|improve this answer
Thank you. It felt like a catch-22, but using a continuation Task to send the cancellation token is a great solution. –  Dan Bailiff May 11 '12 at 15:17

Your Answer


