473,569 Members | 2,836 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

System.Threadin g.Thread.Suspen d/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(thre adtoDump) from a different thread other than the
treadToDump the threadToDump must be suspended otherwise a
ThreadStateExce ption gets thrown.

However under .NET 2.0 System.Threadin g.Thread.Suspen d/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 6040
On Tue, 12 Jun 2007 22:25:00 -0700, Mark Channing <Mark
<Ch******@discu ssions.microsof t.com>wrote:
[...]
However under .NET 2.0 System.Threadin g.Thread.Suspen d/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******@discu ssions.microsof t.com>wrote:
[...]
However under .NET 2.0 System.Threadin g.Thread.Suspen d/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**********@d iscussions.micr osoft.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
3542
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 the synchronized method to get a synchronized Hashtable. The documentation says that enumerating is not a thread safe operation; even using a...
11
2743
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 halted. If a socket is no longer in the configuration, that thread must be aborted and the socket must be closed. After the configuration is...
7
1597
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 like this: public void ExecuteScalar(string query) { this.query = query; this.workingThread.Resume(); //the worker thread is suspended
7
2673
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 a lock pending, for example. I want to be able to stop a thread temporarily, and then optionally resume it or stop it for good.
2
1080
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 after user has selected option to resume execution then only i want to execute remaining part of thread procedure. Currently i am using suspend...
4
1450
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 and sends their content via msmq. The part that iterates and sends the files is in a separate thread. I have a button on the form that allows the...
9
1490
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 initial code loaded the object model and then initialized the communications on the same thread, which took a lot of time. It took a minute plus to...
15
2066
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 synchronization objects instead and oh by the way you shouldn't be using them as they can cause deadlock and other major problems, screams bug or threading...
6
10251
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 the risk of changing the code everywhere so here is what I think I could do, which is to create my own ThreadWrapper class which inherits from...
0
7695
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.