473,796 Members | 2,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Thread.Suspend and Thread.Resume in Framework 2.0

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 original code can work as normal by just referencing my
ThreadWrapper class.

Example

public class ThreadWrapper : Thread
{
public void Abort()
{
// What do i do here
}
public void Suspend()
{
// What do i do here
}
public void Resume()
{
// What do i do here
}
}

My App
public class Test
{
static void Main(string[] args)
{
ThreadWrapper tw = new ThreadWrapper() ;
...
tw.Suspend();
tw.Resume();
tw.Abort();
}
}
Thanks,
Dec 14 '06 #1
6 10272
Why do you need to suspend and resume threads in your app? Could that be a
sign of poor engineering? Please explain.
While "suspending " a thread in the traditional manner has been deprecated by
MSFT, "pausing" a thread between atomic operations (under the developer's
control) is certainly a legitimate requirement :)
Dec 14 '06 #2
"Larry Smith" <no_spam@_nospa m.comwrote
>Why do you need to suspend and resume threads in your app? Could that be
a
sign of poor engineering? Please explain.

While "suspending " a thread in the traditional manner has been deprecated
by MSFT, "pausing" a thread between atomic operations (under the
developer's control) is certainly a legitimate requirement :)
I don't think that's really legit - if I were to see code that was manually
freezing and thawing threads, I would kick it back to the developer and tell
him to re-write it. He would have to come back with a VERY strong reason why
he's doing it.

The standard thread synchronization mechanisms are pretty rich - monitor /
mutes / semaphore / rwlock / event / Interlocked. Other than debugging
scenarios, I don't see the need to externally start/stop threads very often.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins
Dec 14 '06 #3
Hi

I do not see any advantage of moving start, stop, suspend, resume a
thread to a separate class. They are in a single class already and are
static.... what else you need..

Thanks
-Srinivas.

Buddy Home wrote:
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 original code can work as normal by just referencing my
ThreadWrapper class.

Example

public class ThreadWrapper : Thread
{
public void Abort()
{
// What do i do here
}
public void Suspend()
{
// What do i do here
}
public void Resume()
{
// What do i do here
}
}

My App
public class Test
{
static void Main(string[] args)
{
ThreadWrapper tw = new ThreadWrapper() ;
...
tw.Suspend();
tw.Resume();
tw.Abort();
}
}
Thanks,
Dec 14 '06 #4
I don't think that's really legit - if I were to see code that was
manually freezing and thawing threads, I would kick it back to the
developer and tell him to re-write it. He would have to come back with a
VERY strong reason why he's doing it.
I'm glad I don't work for you :)
The standard thread synchronization mechanisms are pretty rich - monitor /
mutes / semaphore / rwlock / event / Interlocked. Other than debugging
scenarios, I don't see the need to externally start/stop threads very
often.
Of course you apply proper synchronization techniques when required. And you
certainly don't pause a thread as a means of synchronization . You use one of
the techniques you cited. If a user clicks the "Cancel" button to abort a
background operation however (for example), and you then display a "confirm
cancellation" dialog for the user, normally you'll want to signal a "pause"
event so the background thread can temporarily suspend itself until the user
exits the dialog (the thread will respect the "pause" event by periodically
testing for it).
Dec 14 '06 #5
Let me get my point out.

I'm aware that it's bad design to suspend and pause the thread but I've got
a task to convert the code from Framework 1.0 to 2.0 and I was trying to get
rid of all the obsolete warning messages in the code. There are approx 200
warnings which call Suspend, Resume and Abort methods of the thread class. I
don't really have the time in my project plan to rewrite all this code so I
was looking for a generic approx which is why I showed the snippet code in
my original post.

Thanks,

"Peter Bromberg [C# MVP]" <pb*******@yaho o.nospammin.com wrote in message
news:EC******** *************** ***********@mic rosoft.com...
Why do you need to suspend and resume threads in your app? Could that be a
sign of poor engineering? Please explain.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Buddy Home" wrote:
>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 original code can work as normal by just referencing my
ThreadWrappe r class.

Example

public class ThreadWrapper : Thread
{
public void Abort()
{
// What do i do here
}
public void Suspend()
{
// What do i do here
}
public void Resume()
{
// What do i do here
}
}

My App
public class Test
{
static void Main(string[] args)
{
ThreadWrapper tw = new ThreadWrapper() ;
...
tw.Suspend();
tw.Resume();
tw.Abort();
}
}
Thanks,

Dec 14 '06 #6
Let me get my point out.

I'm aware that it's bad design to suspend and pause the thread but I've got
a task to convert the code from Framework 1.0 to 2.0 and I was trying to get
rid of all the obsolete warning messages in the code. There are approx 200
warnings which call Suspend, Resume and Abort methods of the thread class. I
don't really have the time in my project plan to rewrite all this code so I
was looking for a generic approx which is why I showed the snippet code in
my original post.

Thanks,

"Larry Smith" <no_spam@_nospa m.comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
>I don't think that's really legit - if I were to see code that was
manually freezing and thawing threads, I would kick it back to the
developer and tell him to re-write it. He would have to come back with a
VERY strong reason why he's doing it.

I'm glad I don't work for you :)
>The standard thread synchronization mechanisms are pretty rich - monitor
/ mutes / semaphore / rwlock / event / Interlocked. Other than debugging
scenarios, I don't see the need to externally start/stop threads very
often.

Of course you apply proper synchronization techniques when required. And
you certainly don't pause a thread as a means of synchronization . You use
one of the techniques you cited. If a user clicks the "Cancel" button to
abort a background operation however (for example), and you then display a
"confirm cancellation" dialog for the user, normally you'll want to signal
a "pause" event so the background thread can temporarily suspend itself
until the user exits the dialog (the thread will respect the "pause" event
by periodically testing for it).

Dec 14 '06 #7

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

Similar topics

1
1656
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?
2
2517
by: SpookyET | last post by:
How do you pause and resume some work without using Thread.Suspend and Thread.Resume since they are deprecated in .NET 2.0?
1
2333
by: Jorge | last post by:
Hi Noor If your process IS a service then yes you suspend or resume it. Kind Regards Jorge
2
503
by: White Spirit | last post by:
I've read that it is not recommended to use Thread.Suspend and Thread.Resume to control execution of threads and that use of the Monitor class is preferred. I'm writing a server that lets users chat together using a GTK# text window and use of Thread.Suspend and Thread.Resume seems to be the only way to achieve this. The server has two arrays of threads. One thread array is for each client to attach to a port (say 1024) to receive the...
4
3201
by: wanwan | last post by:
I'm using Microsoft Visual Studio 2005 in multithreading, I want to be able to pause and resume a thread. I see that suspend and resume are deprecated. So what can I use instead.
4
4613
by: fAnSKyer/C# newbie | last post by:
I am using winmm.dll and I found that I can't just suspend it and resume it? What should I do? Any better idea? Should I use thread? and thread.suspend will work? Thanks
3
6060
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...
1
4086
by: Mike Fellows | last post by:
Having not used threads for such a long time in vb.net I have found myself in need of them I have a thread that runs and retirieves live data from a SQL database, this is running fine and has been doing its job for a long time the problem is I need to suspend this thread when a checkbox is clicked (as the data is no longer required) but when the checkbox is unclicked it needs to restart
0
1588
EARNEST
by: EARNEST | last post by:
Hello again, I would like to put my thread on hold and check the data that the threaded process' event passed to my other class. I am using suspend and resume methods, but the VS says they are obsolete. What should I do? Should I use Sleep with all the time incremental dynamic time slice or there are other ways? Thanks, EARNEST.
0
9685
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10461
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
10239
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
10190
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
10019
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9057
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...
0
6796
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4122
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

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.