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!

Samstag, 8. Februar 2014

shorter term of exception handling with the help of the Ternary operator

For example:

catch (System.ServiceModel.FaultException<AnyContract.ValidationError> ex)
                Console.WriteLine(ex.Detail != null ? ex.Detail.Message : ex.InnerException != null ? ex.InnerException.Message : ex.Message);


catch (Exception ex)
                Console.WriteLine(ex.InnerException != null ? ex.InnerException.Message : ex.Message);

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