How to get Thread State
-
As you know there is no API to get thread current working state (Suspended, running, etc) I need to check a thread working state. I have ThreadId and ThreadHandle. I know there is a way to get thread state, but i don't know what it is! Can anybody help?
modified on Sunday, June 29, 2008 12:45 AM
-
As you know there is no API to get thread current working state (Suspended, running, etc) I need to check a thread working state. I have ThreadId and ThreadHandle. I know there is a way to get thread state, but i don't know what it is! Can anybody help?
modified on Sunday, June 29, 2008 12:45 AM
See if this article is helpful: VC++ MFC Thread Tutorial[^] You can use thread state for debugging purpose but may not be for synchronization as per this one: Thread..::.ThreadState Property [^] -- "Programming is an art that fights back!"
-
As you know there is no API to get thread current working state (Suspended, running, etc) I need to check a thread working state. I have ThreadId and ThreadHandle. I know there is a way to get thread state, but i don't know what it is! Can anybody help?
modified on Sunday, June 29, 2008 12:45 AM
GetExitCodeThread() will check if the thread is active or not. You shouldn't be suspending threads so that shouldn't be an issue, unless you're writing a debugger. There's no reliable way to get the suspended state - that state can change at any time. You could use SuspenfThread() and check the return value. If it returns >= 1 then the thread was already suspended. Don't forget to call ResumeThread(). Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
GetExitCodeThread() will check if the thread is active or not. You shouldn't be suspending threads so that shouldn't be an issue, unless you're writing a debugger. There's no reliable way to get the suspended state - that state can change at any time. You could use SuspenfThread() and check the return value. If it returns >= 1 then the thread was already suspended. Don't forget to call ResumeThread(). Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
Mark Salsbery wrote:
GetExitCodeThread() will check if the thread is active or not.
Thanks, this can help.
Mark Salsbery wrote:
There's no reliable way to get the suspended state - that state can change at any time. You could use SuspenfThread() and check the return value. If it returns >= 1 then the thread was already suspended. Don't forget to call ResumeThread().
Good idea , but I don't want to change thread state, and the thread shouldn't suspend even a millisecond.
-
As you know there is no API to get thread current working state (Suspended, running, etc) I need to check a thread working state. I have ThreadId and ThreadHandle. I know there is a way to get thread state, but i don't know what it is! Can anybody help?
modified on Sunday, June 29, 2008 12:45 AM
If found how to check thread suspended state. With ResumeThread. Here MSDN help: The ResumeThread function checks the suspend count of the subject thread. If the suspend count is zero, the thread is not currently suspended. Otherwise, the subject thread's suspend count is decremented. If the resulting value is zero, then the execution of the subject thread is resumed. If the return value is zero, the specified thread was not suspended. If the return value is 1, the specified thread was suspended but was restarted. If the return value is greater than 1, the specified thread is still suspended.