如何重新启动“已停止”线? [英] How to restart "Stopped" thread?
问题描述
我有第二个线程,t2,错误输出并将停止。它的状态是
然后停止。我尝试从线程1,t1开始t2,检查
如果t2.threadstate =" Stopped"那么
t2.start()
然而,这会引发错误:
System.Threading.ThreadStateException :线程正在运行或终止;它没有重启。
这个线程如何重启?
另外,我怎么放一个线程在已停止中州?这是通过
thread.abort()吗?
谢谢,
Brett
通常你会启动一个新线程。 thread.abort不允许再次启动
线程。我想如果你做一个thread.suspend你可以
重启它。
克里斯
" Brett" ; < no@spam.com>在消息中写道
新闻:eT ************** @ TK2MSFTNGP12.phx.gbl ...我有第二个帖子,t2,错误输出并将停止。它的状态是
然后停止。我尝试从线程1,t1开始t2,检查
如果t2.threadstate =" Stopped"那么
t2.start()
但是,这会引发错误:
System.Threading.ThreadStateException:线程正在运行或终止;它无法重启。
这个线程如何重启?
另外,如何将线程置于已停止状态?州?这是通过
thread.abort()吗?
谢谢,
Brett
"布雷特" < no@spam.com> schrieb:我有第二个线程t2,它出错并将停止。它的状态是
然后停止。我尝试从线程1,t1开始t2,检查
如果t2.threadstate =" Stopped"那么
t2.start()
但是,这会引发错误:
System.Threading.ThreadStateException:线程正在运行或终止;它无法重启。
这个线程如何重启?
如果某个帖子的状态为''已停止'',则该主题要么回复
''中止''请求,要么是终止。创建一个新线程,而不是使用已停止的线程处理
。
此外,如何将线程放入已停止线程中。州?这是通过
thread.abort()吗?
是的。
-
MS Herfried K. Wagner
MVP< URL:http://dotnet.mvps.org/>
VB< URL:http:// dotnet.mvps.org/dotnet/faqs/>
我明白了。现在我这样做是为了在Form1
加载时创建新线程:
Public NewThread As New Class1
Public t As System.Threading.Thread = New System.Threading.Thread(New
System.Threading.ThreadStart(AddressOf NewThread.callSomeSub))
发生在外面任何子。我有一个按钮,最初做t.start()。
一旦线程被停止并且无法重新启动,你说我需要
来创建另一个/新线程。我怎么能在这个
按钮的sub()中做到这一点?我不能宣布公开因为我会得到:
公共在本地变量声明中无效
我需要新的线程是公共的,所以Form1中的sub()可以访问它。
谢谢,
Brett
克里斯,无所不能的主人 < chris@No_Spam_Please.com>在消息新闻中写道:
:u5 ************** @ tk2msftngp13.phx.gbl ...通常你会开始一个新线程。 thread.abort不允许再次启动该线程。我想如果你做一个thread.suspend,你可以重启它。
克里斯
布雷特 < no@spam.com>在消息中写道
新闻:eT ************** @ TK2MSFTNGP12.phx.gbl ...我有第二个帖子,t2,那个错误并将停止。它的状态是
然后停止。我尝试从线程1,t1开始t2,检查
如果t2.threadstate =" Stopped"那么
t2.start()
然而,这引发了错误:
System.Threading.ThreadStateException:线程正在运行或终止;
它无法重新启动。
这个线程如何重启?
另外,如何将一个线程置于已停止状态。州?这是通过
thread.abort()吗?
谢谢,
Brett
I have a second thread, t2, that errors out and will stop. It''s status is
then "Stopped". I try to start t2 from thread 1, t1, by checking
If t2.threadstate = "Stopped" Then
t2.start()
However, this throws and error:
System.Threading.ThreadStateException: Thread is running or terminated; it
can not restart.
How can this thread restart?
Also, how to I put a thread in a "Stopped" state? Is this through
thread.abort()?
Thanks,
Brett
Typically you would start a new thread. thread.abort will not allow that
thread ever to start again. I think if you do a thread.suspend you can
restart it.
Chris
"Brett" <no@spam.com> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...I have a second thread, t2, that errors out and will stop. It''s status is
then "Stopped". I try to start t2 from thread 1, t1, by checking
If t2.threadstate = "Stopped" Then
t2.start()
However, this throws and error:
System.Threading.ThreadStateException: Thread is running or terminated; it
can not restart.
How can this thread restart?
Also, how to I put a thread in a "Stopped" state? Is this through
thread.abort()?
Thanks,
Brett
"Brett" <no@spam.com> schrieb:I have a second thread, t2, that errors out and will stop. It''s status is
then "Stopped". I try to start t2 from thread 1, t1, by checking
If t2.threadstate = "Stopped" Then
t2.start()
However, this throws and error:
System.Threading.ThreadStateException: Thread is running or terminated; it
can not restart.
How can this thread restart?
If a thread''s state is ''Stopped'', the thread is either responding to an
''Abort'' request or it is terminated. Create a new thread instead of dealing
with the stopped thread.
Also, how to I put a thread in a "Stopped" state? Is this through
thread.abort()?
Yes.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
I see. Right now I do this to create the new thread initially when Form1
loads:
Public NewThread As New Class1
Public t As System.Threading.Thread = New System.Threading.Thread(New
System.Threading.ThreadStart(AddressOf NewThread.callSomeSub))
The occurs outside of any sub. I have a button to do t.start() initially.
Once the thread is "stopped" and cannot be restarted, you''re saying I need
to create another/new thread. How can I do that in the sub() of this
button? I can''t declare Public because I''ll get:
Public is not valid on local variable declaration
I need the new thread to be public so sub()s in Form1 can access it.
Thanks,
Brett
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:u5**************@tk2msftngp13.phx.gbl...Typically you would start a new thread. thread.abort will not allow that
thread ever to start again. I think if you do a thread.suspend you can
restart it.
Chris
"Brett" <no@spam.com> wrote in message
news:eT**************@TK2MSFTNGP12.phx.gbl...I have a second thread, t2, that errors out and will stop. It''s status is
then "Stopped". I try to start t2 from thread 1, t1, by checking
If t2.threadstate = "Stopped" Then
t2.start()
However, this throws and error:
System.Threading.ThreadStateException: Thread is running or terminated;
it can not restart.
How can this thread restart?
Also, how to I put a thread in a "Stopped" state? Is this through
thread.abort()?
Thanks,
Brett
这篇关于如何重新启动“已停止”线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!