what is the correct way to cancel multiple tasks in c#
Yeah, what you said about using a single CancellationToken is correct. You can create a single CancellationTokenSource and use its CancellationToken for all of the tasks. Your tasks should check the token regularly for cancellation. For example: const int NUM_TASKS = 4; CancellationTokenSource cts = new CancellationTokenSource(); CancellationToken ct = cts.Token; Task[] tasks = new … Read more