avatar
Thread suspend and resume# DotNet - 窗口里的风景
a*e
1
I just found that in .net framework 2.0 Beta Thread.Suspend() and
Thead.Resume() will be depreciated. I also read some articles from the web
stating that it is better not using those two functions (but no detailed
explanation was given). So I am wondering what is the best alternative for
those two functions. Any ideas?
Thanks.
avatar
c*o
2
http://blogs.msdn.com/oldnewthing/archive/2003/12/09/55988.aspx
Why you should never suspend a thread
It's almost as bad as terminating a thread.
Instead of just answering a question, I'm going to ask you the questions and
see if you can come up with the answers.
Consider the following program, in (gasp) C#:
using System.Threading;
using SC = System.Console;
class Program {
public static void Main() {
Thread t = new Thread(new ThreadStart(Program.worker));
t.Start();
SC.WriteLine("

【在 a******e 的大作中提到】
: I just found that in .net framework 2.0 Beta Thread.Suspend() and
: Thead.Resume() will be depreciated. I also read some articles from the web
: stating that it is better not using those two functions (but no detailed
: explanation was given). So I am wondering what is the best alternative for
: those two functions. Any ideas?
: Thanks.

avatar
a*e
3

Yeah I have read that article. The problem is that I cannot find a good
alternative for Thread.Suspend and Thread.Resume. For example, if I have a
worker thread which does sth taking a long time (a process which is not a
loop) and the user would like to have the option to suspend and resume the
process, what is the best way to do this in .Net?
Any suggestion?
Thanks.
if
System.Console.WriteLine,

【在 c******o 的大作中提到】
: http://blogs.msdn.com/oldnewthing/archive/2003/12/09/55988.aspx
: Why you should never suspend a thread
: It's almost as bad as terminating a thread.
: Instead of just answering a question, I'm going to ask you the questions and
: see if you can come up with the answers.
: Consider the following program, in (gasp) C#:
: using System.Threading;
: using SC = System.Console;
: class Program {
: public static void Main() {

avatar
R*t
4
I got just what you need,
http://msdn.microsoft.com/msdnmag/issues/03/02/Multithreading/
use AsyncOperation as the base class of your worker thread, and override
DoWork, and provide various event handlers like OnComplete, OnCancelled,
you will be able to get notified on completion, on failure, or even cancel
the operation in different ways.
good luck.

【在 a******e 的大作中提到】
:
: Yeah I have read that article. The problem is that I cannot find a good
: alternative for Thread.Suspend and Thread.Resume. For example, if I have a
: worker thread which does sth taking a long time (a process which is not a
: loop) and the user would like to have the option to suspend and resume the
: process, what is the best way to do this in .Net?
: Any suggestion?
: Thanks.
: if
: System.Console.WriteLine,

avatar
m*t
5
It's funny that they had to go through the full length even
after Java did exactly the same 4 years ago.

【在 a******e 的大作中提到】
: I just found that in .net framework 2.0 Beta Thread.Suspend() and
: Thead.Resume() will be depreciated. I also read some articles from the web
: stating that it is better not using those two functions (but no detailed
: explanation was given). So I am wondering what is the best alternative for
: those two functions. Any ideas?
: Thanks.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。