473,416 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

System.Threading.Thread.Suspend/Resume and StackTrace

I have a code which registers all threads with a thread dump class. At
intervals this thread dump class will dump the stack trace of all threads.
As calling StackTrace(threadtoDump) from a different thread other than the
treadToDump the threadToDump must be suspended otherwise a
ThreadStateException gets thrown.

However under .NET 2.0 System.Threading.Thread.Suspend/Resume have been
marked as obsolete with reference to better methods of synchronisation. I
agree with the comment about synchronisation however I am not trying to
sychonise threads, I just need the thread in an ok state to run the
Stacktrace method.

Any suggestions to how this should be achieved.
Jun 13 '07 #1
3 6021
On Tue, 12 Jun 2007 22:25:00 -0700, Mark Channing <Mark
<Ch******@discussions.microsoft.com>wrote:
[...]
However under .NET 2.0 System.Threading.Thread.Suspend/Resume have been
marked as obsolete with reference to better methods of synchronisation.
I
agree with the comment about synchronisation however I am not trying to
sychonise threads, I just need the thread in an ok state to run the
Stacktrace method.

Any suggestions to how this should be achieved.
Just use Suspend() and Resume(). They are still necessary in certain
cases, and your situation would be one of them. No, they are not the
right way to deal with thread synchronization issues, but if you can't get
the stack trace of a thread without suspending it, then you need to
suspend it if you want to get the stack trace (seems obvious, no? :) ).

Sounds like you're doing a sampling profiler? :)

Pete
Jun 13 '07 #2
Thanks for you response. I have no issues with using Suspend Resume methods.
However when reading the link that comes with the build warning, obsolete,
may be removed in future releases then I supposed there must be another way.

The code is some in application that I have moved onto and was added to trap
deadlocks. If GUI thread was running user can invoke thread dumper to output
all threads to find where some non GUI thread was locked. Alternatively if
GUI was locking regularly we could enable a timer thread to dump threads at
certain intervals. Personally I am not keen on either approach and would
expect some external tool that could do a core dump would be a better
approach.

"Peter Duniho" wrote:
On Tue, 12 Jun 2007 22:25:00 -0700, Mark Channing <Mark
<Ch******@discussions.microsoft.com>wrote:
[...]
However under .NET 2.0 System.Threading.Thread.Suspend/Resume have been
marked as obsolete with reference to better methods of synchronisation.
I
agree with the comment about synchronisation however I am not trying to
sychonise threads, I just need the thread in an ok state to run the
Stacktrace method.

Any suggestions to how this should be achieved.

Just use Suspend() and Resume(). They are still necessary in certain
cases, and your situation would be one of them. No, they are not the
right way to deal with thread synchronization issues, but if you can't get
the stack trace of a thread without suspending it, then you need to
suspend it if you want to get the stack trace (seems obvious, no? :) ).

Sounds like you're doing a sampling profiler? :)

Pete
Jun 13 '07 #3
On Wed, 13 Jun 2007 01:28:00 -0700, Mark Channing
<Ma**********@discussions.microsoft.comwrote:
Thanks for you response. I have no issues with using Suspend Resume
methods.
However when reading the link that comes with the build warning,
obsolete,
may be removed in future releases then I supposed there must be another
way.
I suppose that's a theoretical possibility. But I'd be very surprised if
Suspend() and Resume() were ever removed. Windows is chock full of
"obsolete" APIs, some dating way back to the earliest days of the OS.
This is in fact one great thing about Windows and perhaps its biggest
Achilles heel: Microsoft invests significant resources in ensuring that
legacy applications still work as the OS evolves.

I can't guarantee you that the methods won't be removed, but it would sure
surprise me if they were. At the very minimum, long before they are
completely unavailable to any application you won't be able to compile new
code using them.

Also...
The code is some in application that I have moved onto and was added to
trap
deadlocks. If GUI thread was running user can invoke thread dumper to
output
all threads to find where some non GUI thread was locked.
This sounds to me as though it's a temporary diagnostic sort of thing. A
multi-threaded application should not have deadlocking code, and in the
long-term the goal should be to simply have correctly written code that
doesn't deadlock in the first place. Even more reason to not worry about
the long-term viability of Suspend() and Resume().
[...] Personally I am not keen on either approach and would
expect some external tool that could do a core dump would be a better
approach.
Well, a debugger comes to mind. :) But I'm sorry to say, I don't know
off the top of my head a special-purpose utility to do stack dumps. It
does seem like one could easily be written: it would act a lot like a
debugger, in that it would have to attach to the process and interrupt it,
but all it would have to do is use a PDB file to trace all of the stack
traces for each thread. How that would work with .NET code I don't know,
but I'm sure it's possible. :)

One advantage to using the external tool is that your application need not
be reliant on potentially removed methods, not would it have to carry
around diagnostic code that doesn't contribute to the application's main
purpose.

Pete
Jun 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Carlos Kirkconnell | last post by:
I'm programming a multi - threaded application using C#. I have two questions regarding to the use of threads 1- I have a Hashtable that will have multiple writters and multiple readers. I used...
11
by: Keith Langer | last post by:
I have an application which consists of a main work thread and multiple threads which each maintain a TCP socket. When a configuration change occurs, all activity on the socket threads must be...
7
by: SharpCoderMP | last post by:
hi, i have a problem: i wrote a class that encapsulates communication with database. i wont go into details, but i wanted to use threads to avoid unresponsive ui so i did something more or less...
7
by: Charles Law | last post by:
My first thought was to call WorkerThread.Suspend but the help cautions against this (for good reason) because the caller has no control over where the thread actually stops, and it might have...
2
by: trialproduct2004 | last post by:
Hi all i am having problem in vb.net application. I am having one thread which is currently running. AFter executing some part of thread procedure i want to suspend execution of thread and only...
4
by: MS | last post by:
Hi. I'm new to developing and c#. I'm developing a tool that allows a user to select a directory with specially formatted files. The tool then iterates through the list of files in the directory...
9
by: russ.haley | last post by:
Threading and suspend I have an application that will load x number of "communicators". These "communicators" start up a communications channel with another application(of no importance). The...
15
by: WXS | last post by:
When I see things in .NET 2.0 like obsoletion of suspend/resume because of the public reason MS gives of they think people are using them inappropriately.. use mutex, monitor and other...
6
by: Buddy Home | last post by:
Hello, I want to understand whats the best way to write code to replace Thread.Suspend, Thread.Resume and Thread.Abort. I have lots of code calling these existing methods and want to minimize...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.