Reputation: 2194
I am writing a C# console application to find if there are any OUTLOOK processes which are suspended. Occasionally on our Terminal server, Outlook will lock up on a session and will get stuck as "Suspended" in Task Manager.
I found this code on a website as an example to checking if a notepad process is suspended:
var proc = Process.GetProcessesByName("notepad");
var isSuspended = proc[0].Threads[0].ThreadState == ThreadState.Suspended;
I tried this exact code, but the only ThreadStates that are possible are:
- Initalized
- Ready
- Running
- Standby
- Terminated
- Transition
- Unknown
- Wait.
There isn't one for "Suspended" as far as I can see. Is there an alternative method for checking for suspended processes?
Upvotes: 3
Views: 5678
Reputation: 239664
Having established that the thread is waiting via it's ThreadState
, you can examine the WaitReason
property of the ProcessThread
and see if that says it's Suspended
.
Obviously, there are timing issues with performing tests such as these, since the other process is outside of your control.
Upvotes: 3