diff --git a/cYo.Common/Threading/ThreadUtility.cs b/cYo.Common/Threading/ThreadUtility.cs index ac5fbd4..49d1694 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($"{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) {