I have this asynchronous method :
private static async Task Initializ( ) { /*Do Stuff Here*/ }
I want to be able to monitor the task that results from calling this function :
Task T = Class.Initialize( );
if (T.IsCancelled){ /*Do Stuff Here*/ }
I have in place a CancellationTokenSource
.
How can I make T
(or the function Initialize
) utilize that sources token such that if it is cancelled, T.IsCancelled
will be true?
EDIT
I do not know for certain but I think the answer to my question lies within using a TaskCompletionSource
object. The answer given by Mike has lead me to this conclusion...