Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
catch thread exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Higgins committed Oct 10, 2020
1 parent afefd2a commit 148602d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions CenterTaskbar/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,19 @@ private void CancelPositionThread()
_loopCancellationTokenSource.Cancel();
Parallel.ForEach(_positionThreads.Values.ToList(), theTask =>
{
// Give the thread time to exit gracefully.
if (theTask.Wait(OneSecond * 3)) return;

Debug.WriteLine("Timeout waiting for task to cancel!");
theTask.Dispose();
try
{
// Give the thread time to exit gracefully.
if (theTask.Wait(OneSecond * 3)) return;
}
catch (OperationCanceledException e)
{
Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
}
finally
{
theTask.Dispose();
}
});

_loopCancellationTokenSource = new CancellationTokenSource();
Expand Down

0 comments on commit 148602d

Please sign in to comment.