Thread.IsAlive和Thread.ThreadState == ThreadState.Running [英] Thread.IsAlive and Thread.ThreadState==ThreadState.Running

查看:1786
本文介绍了Thread.IsAlive和Thread.ThreadState == ThreadState.Running的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用与如果(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?

推荐答案

MSDN Thread.IsAlive物业
如果此线程已启动,并已不能正常中止或终止;否则为false。

msdn Thread.IsAlive Property true if this thread has been started and has not terminated normally or aborted; otherwise, false.

MSDN 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆