Home All Groups Group Topic Archive Search About

create new StackTrace-object for a thread

Author
2 Apr 2007 11:50 AM
Markus Eßmayr
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

Author
3 Apr 2007 3:32 AM
Lloyd Dupont
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...


Show quote
"Markus Eßmayr" <essmayr/at/racon-linz.at> wrote in message
news:OTKXp0RdHHA.4032@TK2MSFTNGP02.phx.gbl...
> 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
>

AddThis Social Bookmark Button