Sonntag, 30. November 2014

How to cancel a parallel task

a) THREAD A:  The method for the starting of the parallel task instantiates a new System.Threading.CancellationTokenSource Object

b) THREAD A: This CancellationTokenSource is given to the parallel task

c) THREAD B: The underlying method of the parallel task includes the type of CancellationTokenSource in its signature to take it over.

If a "cancel" button was pushed in THREAD A, then CancellationTokens method Cancel must be raised. This is done like this:

The routine inside THREAD B (expecting while...wend loop for instance) is checking the CancellationTokenSource.Token.IsCancellationRequested = true
state and aborts its work in this case.


based information :

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

Keine Kommentare:

Kommentar veröffentlichen