Open joseangelmt opened 5 years ago
I was running into the same TaskCancelledException
being thrown and crashing the application with "Unhandled exception..." error message. I can confirm this solution does work with the latest .NET 6.0 on Linux. The other solution I had working was wrapping the Task.Delay(-1, cts.Token);
call in a try-catch block to handle the exception. Both solutions work.
The call to
await Task.Delay(-1, cts.Token)
throws and exception of typeTaskCancelledException
, so the lineConsole.WriteLine("Exiting...");
is never executed and the program is finalized with the exception.I think could be a better solution to use
TaskCompletionSource
insteadCancellationTokenSource
like this: