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);
}