Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I recommend using the <code>Task</code> class (added in .NET 4.0) if you need this kind of behaviour. It supports <em>cancellation</em>, and you can have any number of tasks listening to the same cancellation token, which enables you to cancel them all with a single method call.</p> <p><strong>Updated (non-4.0 solution):</strong></p> <p>You really only have two choices. One: implement your own event demultiplexer (this is far more complex than it appears, due to the 64-handle wait limitation); I can't recommend this - I had to do it once (in unmanaged code), and it was hideous.</p> <p>That leaves the second choice: Have a signal to cancel the tasks. Naturally, <code>RegisteredWaitHandle.Unregister</code> can cancel the RWFSO part. The QUWI is more complex, but can be done by making the action aware of a "token" value. When the action executes, it first checks the token value against its stored token value; if they are different, then it shouldn't do anything.</p> <p>One major thing to consider is race conditions. Just keep in mind that there is a race condition between cancelling an action and the ThreadPool executing it, so it is possible to see actions running after cancellation.</p> <p>I have <a href="http://nitoprograms.blogspot.com/2009/04/asynchronous-callback-contexts.html" rel="nofollow noreferrer">a blog post on this concept</a>, which I call "asynchronous callback contexts". The <code>CallbackContext</code> type mentioned in the blog post is available in the <a href="http://nitoasync.codeplex.com/" rel="nofollow noreferrer">Nito.Async</a> library.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload