Hi,
in my application I need to get the current executing location of a thread.
Until now I did this by
Thread executingThread;
...
executingThread.Suspend();
StackTrace executionLocation = new StackTrace(executingThread, false);
executingThread.Resume();
...
This works very good.
Since .NET Framework 2.0 the Suspend and Resume functions are marked
obsolete.
But the documentation of the StackTrace constructor still says "If a
StackTrace is created with a target thread that is not the current thread,
the target thread must first be suspended."
Can anyone please tell me how to suspend a thread without using
Thread.Suspend?
Thanks in advance!
Max
Lloyd Dupont - 03 Apr 2007 04:32 GMT
It's obsolete because....
the little caution box in the documenttation, down the page.
Let me copy it there for you:
---
Do not use the Suspend and Resume methods to synchronize the activities of
threads. You have no way of knowing what code a thread is executing when you
suspend it. If you suspend a thread while it holds locks during a security
permission evaluation, other threads in the AppDomain might be blocked. If
you suspend a thread while it is executing a class constructor, other
threads in the AppDomain that attempt to use that class are blocked.
Deadlocks can occur very easily.
---
Meanwhile you could ((almost) safely) use suspend for suspending need...
> Hi,
>
[quoted text clipped - 22 lines]
>
> Max