Reputation: 5124
I'm trying to get a .NET thread state.
For this I check the ProcessThread.ThreadState
property.
However when I use Thread.Sleep
on that thread and check its state with Process Explorer
- I see that it's in "Wait: Delay Exectuion", while my ThreadState is still "Running".
How can that be?
Upvotes: 3
Views: 1390
Reputation: 40838
The Process
class caches properties on first access, so you will probably need to call the Refresh
method to get an updated ThreadState
. It seems that the ProcessThread
objects (from the ProcessThreads
property) are not attached to the parent Process
, and the values it contains are not updated when Refresh
is called. You will need to go through the Process
object again.
Something like:
Process p = Process.GetProcessByName("MyProcess);
while(true)
{
p.Refresh();
Console.WriteLine(p.ProcessThreads[0].ThreadState);
Thread.Sleep(1000);
}
Upvotes: 1