Is my thread in the Ready Queue?
I need to log when and for how long a spe开发者_JAVA百科cific thread is in the Ready Queue. I wonder if there is a programmatic way to do that with C#. Tell me if you need more information...
Thanks in advance, Rotem Varon.
You can check the ThreadState
property of the Thread
object.
See the possibile values here: http://msdn.microsoft.com/en-us/library/system.threading.threadstate.aspx
WaitSleepJoin
indicates it's waiting for something, Running
means it's in the 'ready queue' as far as I know. Hope that helps.
The information about the kernel state of a thread is available in the KTHREAD kernel structure, accessible through the thread block in kernel mode.
The question is how to surface it or expose it to a program in user mode? Probably the best solution given time and skills is to write a kernel driver.
Alternatively you may look to the windows performance counters, which may already do it for you. In any case, you have to resort to rather imprecise polling (you do not get a notification WHEN the thread change state).
The Win32_Thread WMI class may be useful for you, especially the ExecutionState
field.
精彩评论