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

Commit

Permalink
better exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Higgins committed Nov 24, 2020
1 parent 2129f7b commit 5787644
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions CenterTaskbar/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,25 +166,34 @@ private void Exit(object sender, EventArgs e)

private void CancelPositionThread()
{
_loopCancellationTokenSource.Cancel();
Parallel.ForEach(_positionThreads.Values.ToList(), theTask =>
try
{
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
_loopCancellationTokenSource.Cancel();
Parallel.ForEach(_positionThreads.Values.ToList(), theTask =>
{
theTask.Dispose();
}
});

_loopCancellationTokenSource = new CancellationTokenSource();
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();
}
});
}
catch (OperationCanceledException e)
{
Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
}
finally
{
_loopCancellationTokenSource = new CancellationTokenSource();
}
}

private void Restart(object sender, EventArgs e)
Expand Down

0 comments on commit 5787644

Please sign in to comment.