Skip to content

Commit

Permalink
Merge pull request #7 from apiweb/obsoleteCode
Browse files Browse the repository at this point in the history
Update obsolete Threads code
  • Loading branch information
maforget authored Jan 23, 2024
2 parents dd38232 + 5506a98 commit e1feb28
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions cYo.Common/Threading/ThreadUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit e1feb28

Please sign in to comment.