473,225 Members | 1,394 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,225 software developers and data experts.

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 10231
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@_nospam.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*******@yahoo.nospammin.comwrote in message
news:EC**********************************@microsof t.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
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 #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@_nospam.comwrote in message
news:%2****************@TK2MSFTNGP06.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
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...
2
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
by: Jorge | last post by:
Hi Noor If your process IS a service then yes you suspend or resume it. Kind Regards Jorge
2
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...
4
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
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
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...
1
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...
0
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...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.