473,806 Members | 2,661 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The sin of Suspend()

Hi all!

I'm working on an application that due to the nature of the application
is heavily concurrent. Usually, there will be between 15 and 20 threads
running at the same time. However, at some times it might be necessary
to pause execution of these threads. Thread.Suspend( ) looks like an
excellent candidate, but the method is deprecated in the framework.
According to the documentation I should use dedicated objects like
Monitors for synchronization .

I do understand why using Suspend() for synchronization is a Bad Idea
(TM). But is it a bad idea for pausing (parts of) an application as
well? There is no way of telling which part of the code each thread is
executing and I would hate to have to litter my code with checkPaused()
methods, or something like that.

Does anyone know whether it is a sin to use Suspend() in this case and
why or why not?

Thanks in advance,
Bram Fokke
the Netherlands

Mar 28 '06 #1
2 1637
As long as you are absolutely sure that one thread does not eat the same
piece of memory as another thread, both in managed code and below the
surface, suspend is not that wicked. It is deprecated largely because most
people only examined the surface and ignored what was going on below the
surface.

If you go this route, note that your code is not considered thread safe.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************** ************
Think Outside the Box!
*************** ************
"b.*****@gmail. com" wrote:
Hi all!

I'm working on an application that due to the nature of the application
is heavily concurrent. Usually, there will be between 15 and 20 threads
running at the same time. However, at some times it might be necessary
to pause execution of these threads. Thread.Suspend( ) looks like an
excellent candidate, but the method is deprecated in the framework.
According to the documentation I should use dedicated objects like
Monitors for synchronization .

I do understand why using Suspend() for synchronization is a Bad Idea
(TM). But is it a bad idea for pausing (parts of) an application as
well? There is no way of telling which part of the code each thread is
executing and I would hate to have to litter my code with checkPaused()
methods, or something like that.

Does anyone know whether it is a sin to use Suspend() in this case and
why or why not?

Thanks in advance,
Bram Fokke
the Netherlands

Mar 28 '06 #2
<b.*****@gmail. com> wrote:
I'm working on an application that due to the nature of the application
is heavily concurrent. Usually, there will be between 15 and 20 threads
running at the same time. However, at some times it might be necessary
to pause execution of these threads. Thread.Suspend( ) looks like an
excellent candidate, but the method is deprecated in the framework.
According to the documentation I should use dedicated objects like
Monitors for synchronization .

I do understand why using Suspend() for synchronization is a Bad Idea
(TM). But is it a bad idea for pausing (parts of) an application as
well? There is no way of telling which part of the code each thread is
executing and I would hate to have to litter my code with checkPaused()
methods, or something like that.

Does anyone know whether it is a sin to use Suspend() in this case and
why or why not?


If there is no way to tell where each of the threads are, it sounds
like a really bad idea to call Suspend. What if one of the threads owns
a lock which the other threads need? What if they're half way through
modifying some shared data, leaving it in an inconsistent state?

Is there really no point in your code which is executed sufficiently
regularly that it would make a good point to check for pausing?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 29 '06 #3

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

Similar topics

11
2781
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 complete, the remaining threads must be resumed. I currently have the following architecture:
8
36470
by: Wim | last post by:
My GUI application starts a process (a console program) when the user hits Play. I would like to add an option to pause that process. The code I've added to detect if the user hit pause/unpause seems to work. But I have no clue how to pause/suspend the process. As far as I can see the Process class doesn't offer anything for this. So it's probably the thread the process is running on that should be suspended or put to sleep. But just...
1
1657
by: Paul Tomlinson | last post by:
Quick question. If i call Thread.suspend() on a thread does the thread which is being suspended get any notification that it has been/is being suspended? I am thinking i want the thread-to-be-suspended to log the fact that it is being suspended. Any ideas?
1
2335
by: Jorge | last post by:
Hi Noor If your process IS a service then yes you suspend or resume it. Kind Regards Jorge
2
2304
by: Sakharam Phapale | last post by:
Hi All, In following example, while playing file, if thread goes in WaitSleepJoin state, due to Thread.Sleep method. Now I want to suspend thread by clicking on cmdSuspend button. I have written following code, which doesn't suspend it. Even I tried it by calling m_PlayThread.Interrupt() method which suspends the thread but cannot resume it again by calling Resume method. Any kind help will be appreciated.
2
4317
by: juky | last post by:
Hi all, I have a loop in the thread checking for a particular service status, whenever the status changes to "stopped" a RaiseEvent is generated by thread and another function runs. At the same time the thread is suspended. When I try to resume it from the another function I have some problems. Thank you. Juky
6
1418
by: Robert Speck | last post by:
Hi there, Can anyone shed anymore light on why "Thread.Suspend()" has been deprecated by MSFT beyond what MSDN says about it. I'm not sure if I quite appreciate the various pitfalls they discuss but using it under certain circumstances still seems reasonable. For instance, I want to display a small modal dialog with a "Cancel" button which allows the user to abort a background thread. If the user clicks this button, I then want to prompt...
6
10274
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 Thread and which has these three methods already defined but does it a different way and then my...
3
6062
by: =?Utf-8?B?TWFyayBDaGFubmluZw==?= | last post by:
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...
0
9597
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10620
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10369
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10372
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9187
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5682
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
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
3
3008
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.