From c31211241d2913409683352ed5849b9b8827f970 Mon Sep 17 00:00:00 2001 From: Jaime Bernardo Date: Tue, 19 Sep 2023 15:40:41 +0100 Subject: [PATCH] [MWB]Fix thread suspend crash on process restart (#28609) --- .../MouseWithoutBorders/App/Class/Common.Log.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/modules/MouseWithoutBorders/App/Class/Common.Log.cs b/src/modules/MouseWithoutBorders/App/Class/Common.Log.cs index 4736a74cf6..c343bed3e5 100644 --- a/src/modules/MouseWithoutBorders/App/Class/Common.Log.cs +++ b/src/modules/MouseWithoutBorders/App/Class/Common.Log.cs @@ -90,7 +90,19 @@ namespace MouseWithoutBorders lock (ThreadsLock) { #pragma warning disable 618 // Temporary - threads.Where(t => t.IsAlive && t.ManagedThreadId != threadId).ToList().ForEach(t => t.Suspend()); + threads.Where(t => t.IsAlive && t.ManagedThreadId != threadId).ToList().ForEach( + t => + { + try + { + t.Suspend(); + } + catch (Exception) + { + // This method is suspending every thread so that it can kill the process right after restarting. + // Makes no sense to crash on a thread suspension fail, since we're killing the process afterwards, anyway. + } + }); #pragma warning restore 618 } }