Can someone explain to me the use of Task.Wait (CancellationToken) overload? MSDN really talks a lot about this ...
So I usually handle task cancellation:
var source = new CancellationTokenSource(); var task = Task.Factory.StartNew(() => { while (true) { source.Token.ThrowIfCancellationRequested(); } }, source.Token); try { task.Wait(); } catch (AggregateException exc) { exc.Flatten().Handle(e => e is OperationCanceledException); }
So, when is it useful to pass a token to the Wait method?
source share