From c0bb51d28869d613a2d0c93eaa0a4f06bfe98ba6 Mon Sep 17 00:00:00 2001 From: Apiweb Date: Fri, 19 Jan 2024 08:36:07 -0300 Subject: [PATCH 1/2] Update obsolete code --- cYo.Common/Threading/ThreadUtility.cs | 64 +++++++++++++-------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/cYo.Common/Threading/ThreadUtility.cs b/cYo.Common/Threading/ThreadUtility.cs index ac5fbd4..f735be2 100644 --- a/cYo.Common/Threading/ThreadUtility.cs +++ b/cYo.Common/Threading/ThreadUtility.cs @@ -249,39 +249,37 @@ public static void Abort(Thread thread, int timeOut) } } - private static void DumpThread(TextWriter tw, Thread t) - { - try - { - if (!t.IsAlive) - { - return; - } - tw.WriteLine(new string('-', 20)); - tw.WriteLine("{0}: {1} ({2})", t.Name, t.ThreadState, t.IsBackground ? "B" : string.Empty); - StackTrace stackTrace; - if (t == Thread.CurrentThread) - { - stackTrace = new StackTrace(); - } - else - { - t.Suspend(); - try - { - stackTrace = new StackTrace(t, needFileInfo: true); - } - finally - { - t.Resume(); - } - } - tw.WriteLine(stackTrace.ToString()); - } - catch - { - } - } + private static void DumpThread(TextWriter tw, Thread t) + { + try + { + if (!t.IsAlive) + { + return; + } + + tw.WriteLine(new string('-', 20)); + tw.WriteLine("{0}: {1} ({2})", t.Name, t.ThreadState, t.IsBackground ? "B" : string.Empty); + + StackTrace stackTrace; + if (t == Thread.CurrentThread) + { + stackTrace = new StackTrace(); + } + else + { + lock (t) + { + stackTrace = new StackTrace(true); + } + } + + tw.WriteLine(stackTrace.ToString()); + } + catch + { + } + } public static void DumpStacks(TextWriter tw) { From 5506a98e331cb18458d61661996f67b410613a44 Mon Sep 17 00:00:00 2001 From: maforget <11904426+maforget@users.noreply.github.com> Date: Mon, 22 Jan 2024 20:56:35 -0500 Subject: [PATCH 2/2] changed to interpolated string --- cYo.Common/Threading/ThreadUtility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cYo.Common/Threading/ThreadUtility.cs b/cYo.Common/Threading/ThreadUtility.cs index f735be2..49d1694 100644 --- a/cYo.Common/Threading/ThreadUtility.cs +++ b/cYo.Common/Threading/ThreadUtility.cs @@ -259,7 +259,7 @@ private static void DumpThread(TextWriter tw, Thread t) } tw.WriteLine(new string('-', 20)); - tw.WriteLine("{0}: {1} ({2})", t.Name, t.ThreadState, t.IsBackground ? "B" : string.Empty); + tw.WriteLine($"{t.Name}: {t.ThreadState} ({(t.IsBackground ? "B" : string.Empty)})"); StackTrace stackTrace; if (t == Thread.CurrentThread)