I'm wondering how to use the Task.WaitAll overloads that take a CancellationToken as an argument, e.g. https://msdn.microsoft.com/en-us/library/dd321573%28v=vs.110%29.aspx
The documentation says the CancellationToken argument is "A CancellationToken to observe while waiting for the tasks to complete."
Since Task.WaitAll is a blocking operation, how could you possibly "observe" it during that operation? Furthermore, it says "The cancellationToken argument is used to cancel the wait operation. If it is canceled, the Wait returns false." but then it also says elsewhere that a OperationCanceledException is thrown when the CancellationToken is cancelled, meaning Task.WaitAll doesn't return true or false.
I'm either missing something really simple, or something is wrong with the documentation. Either way, I'm thoroughly confused. My ultimate goal is to be able to wait for multiple tasks to finish or to cancel them gracefully (via the proper use of CancellationToken) if they don't finish within a certain period of time.
This is related to my post here, but this time, I'm writing the async code and can observe the cancellation tokens.
Task.WaitAllis observing the token you pass to it.WaitAlldoesn't cancel the individual tasks. You need to also pass the token to the tasks, and depending on the nature of the task, they also need to explicitly check if the token has been cancelled.CancellationTokenSource.Cancel()on its source. For timeouts this happens through a timer created by the source.CancellationTokenSourcecan cancel it. It is not necessarily main thread.