472,474 Members | 1,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,474 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 10145
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
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
1
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...
1
by: CD Tom | last post by:
I have a table that can contain up to 12 entries for an individual in the number field each number can be different number I want only to add up the top 7 numbers for each individual. What's the...
2
by: RonFreudenheim | last post by:
Hello, I have a tabbed form. On each tab there is a subform. On Subform1 I have a series of combo boxes whose names are Combo1, Combo2, Combo3, etc. and button that if the user clicks will write...
0
by: antdb | last post by:
Ⅱ. Download AntDB Community Version Download at: http://www.antdb.net/download, choose X86 version under Open Euler https://img1.imgtp.com/2023/06/14/hn1P9Kz2.png Ⅲ. Deploy AntDB Community...
2
ADezii
by: ADezii | last post by:
What is the best, comprehensive Reference for programming Windows Applications in VB.NET. I have experience in programming in general, but not VB.NET. Thanks in advance.
0
by: antdb | last post by:
B.Distributed Deployment 1). Deploy the distributed software sh antdb_install.sh ### the difference between distributed and centralized software deployment is as follows...
1
by: iamroshm | last post by:
I am new to Access VBA. We have an Access database which 20 staff are working together . i want a anyone to help me set up the popup message and notification to all the active users. The backend...

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.