Check if a Win32 thread is running or in a suspended state

前端 未结 7 1543
清歌不尽
清歌不尽 2020-12-01 11:26

How do I check to see if a Win32 thread is running or in suspended state?

I can\'t find any Win32 API which gives the state of a thread. So how do I get the thread s

7条回答
  •  情歌与酒
    2020-12-01 11:30

    WMI's Win32_Thread class has a ThreadState property, where 5: "Suspended Blocked" and 6:Suspended Ready.

    You will need the Thread's Id to get the right instance directly (the WMI object's Handle property is the thread id).

    EDIT: Given this PowerShell query:

    gwmi win32_thread | group ThreadState
    

    gives

    Count Name  Group
    ----- ----  -----
        6 2     {, , , ...}
      966 5     {, , , ...}
    

    WMI has a different definition of "Suspended" to Win32.

提交回复
热议问题