问题描述
我使用与如果(Thread.IsAlive)
来检查线程的状态。一种形式是在这个线程运行。在执行过程中时,即使窗体保持打开状态,调用Thread.IsAlive似乎被评估为false。我想执行与如果(Thread.ThreadState == ThreadState.Running)
相同的检查。它是做正确的方法是什么?如果没有,什么是围绕可能的工作?
I am using to check the condition of a thread with if(Thread.IsAlive)
. A form is running in this thread. At times during execution, even though the form remains open, the call to Thread.IsAlive seems to be evaluating to false. I thought to perform the same check with if(Thread.ThreadState==ThreadState.Running)
. Is it the right way to do? If not, what is the possible work around?
推荐答案
的 Thread.IsAlive物业
如果此线程已启动,并已不能正常中止或终止;否则为false。
msdn Thread.IsAlive Propertytrue if this thread has been started and has not terminated normally or aborted; otherwise, false.
的 Thread.ThreadState
msdn Thread.ThreadState
- 运行结果
线程已经启动,这是不堵塞,而且没有挂起的ThreadAbortException。 - StopRequested
- SuspendRequested
- 背景
- 未开始
- WaitSleepJoin
- 暂停
- AbortRequested
- Running
The thread has been started, it is not blocked, and there is no pending ThreadAbortException. - StopRequested
- SuspendRequested
- Background
- Unstarted
- WaitSleepJoin
- Suspended
- AbortRequested
我现在想很明显运行
是不一样的的IsAlive
I think now it's clear Running
is not the same as IsAlive
这篇关于Thread.IsAlive和Thread.ThreadState == ThreadState.Running的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!