Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get Thread State

How to get Thread State

Scheduled Pinned Locked Moved C / C++ / MFC
jsonhelptutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SalarSoft
    wrote on last edited by
    #1

    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?

    http://www.softprojects.org/

    modified on Sunday, June 29, 2008 12:45 AM

    R M S 3 Replies Last reply
    0
    • S SalarSoft

      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?

      http://www.softprojects.org/

      modified on Sunday, June 29, 2008 12:45 AM

      R Offline
      R Offline
      rp_suman
      wrote on last edited by
      #2

      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!"

      1 Reply Last reply
      0
      • S SalarSoft

        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?

        http://www.softprojects.org/

        modified on Sunday, June 29, 2008 12:45 AM

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        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:

        S 1 Reply Last reply
        0
        • M Mark Salsbery

          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:

          S Offline
          S Offline
          SalarSoft
          wrote on last edited by
          #4

          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.

          http://www.softprojects.org/

          1 Reply Last reply
          0
          • S SalarSoft

            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?

            http://www.softprojects.org/

            modified on Sunday, June 29, 2008 12:45 AM

            S Offline
            S Offline
            SalarSoft
            wrote on last edited by
            #5

            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.

            www.softprojects.org

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups