diff --git a/CenterTaskbar/Program.cs b/CenterTaskbar/Program.cs index 786f8b1..d5fa72d 100644 --- a/CenterTaskbar/Program.cs +++ b/CenterTaskbar/Program.cs @@ -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();