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. terminate thread

terminate thread

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 4 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.
  • Z Offline
    Z Offline
    zecodela
    wrote on last edited by
    #1

    hi, what method do you use to terminate a thread? i am in a situation that after few thousands of restart a thread? it failed for me to create thread for me with AfxBeginThread(). i used TerminateThread() to terminate thread from the main program, in msdn, it is not a good method to terminate a thread. i guess it leads to the problem that i can't create thread when restart. do you have any good method to terminate thread? thanks, jim

    R N R 3 Replies Last reply
    0
    • Z zecodela

      hi, what method do you use to terminate a thread? i am in a situation that after few thousands of restart a thread? it failed for me to create thread for me with AfxBeginThread(). i used TerminateThread() to terminate thread from the main program, in msdn, it is not a good method to terminate a thread. i guess it leads to the problem that i can't create thread when restart. do you have any good method to terminate thread? thanks, jim

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

      You can usually end your thread from within the thread with Afxenthread(); If you want to do that remotedely from outside the thread, just use an event to tell your thread to end. ~RaGE();

      Z 1 Reply Last reply
      0
      • Z zecodela

        hi, what method do you use to terminate a thread? i am in a situation that after few thousands of restart a thread? it failed for me to create thread for me with AfxBeginThread(). i used TerminateThread() to terminate thread from the main program, in msdn, it is not a good method to terminate a thread. i guess it leads to the problem that i can't create thread when restart. do you have any good method to terminate thread? thanks, jim

        N Offline
        N Offline
        Nish Nishant
        wrote on last edited by
        #3

        Just return from the threadproc and your thread is terminated. It's not even required that you call AfxEndThread Nish


        Author of the romantic comedy Summer Love and Some more Cricket [New Win]

        1 Reply Last reply
        0
        • R Rage

          You can usually end your thread from within the thread with Afxenthread(); If you want to do that remotedely from outside the thread, just use an event to tell your thread to end. ~RaGE();

          Z Offline
          Z Offline
          zecodela
          wrote on last edited by
          #4

          hi, i found that the thread would not terminate immediately after call AfxEndThread(). since i used TerminateThread() to terminate another thread at the same time, so i can observe such difference. is it normal? thanks, jim

          1 Reply Last reply
          0
          • Z zecodela

            hi, what method do you use to terminate a thread? i am in a situation that after few thousands of restart a thread? it failed for me to create thread for me with AfxBeginThread(). i used TerminateThread() to terminate thread from the main program, in msdn, it is not a good method to terminate a thread. i guess it leads to the problem that i can't create thread when restart. do you have any good method to terminate thread? thanks, jim

            R Offline
            R Offline
            Ramu Pulipati
            wrote on last edited by
            #5

            There are couple of ways to terminate thread safely based on the problem here is the event approach, - CreateEvent() (named event to use across process'es) - CreateThread (or AfxBEginThread) and pass event as Thread Param - Keep listening to Event Signaling at application atomic times (WaitForSingleObject). - when Event is signaled or job is done, just return (use AfxEndThread() with AfxBeginThread() - MFC way) From main/any thread signal the event, when u want to stop the thread safely. To brutally kill the thread use: TerminateThread() Refer to samples in codeproject.com OR codeguru.com. Hth, Ramu

            Z 1 Reply Last reply
            0
            • R Ramu Pulipati

              There are couple of ways to terminate thread safely based on the problem here is the event approach, - CreateEvent() (named event to use across process'es) - CreateThread (or AfxBEginThread) and pass event as Thread Param - Keep listening to Event Signaling at application atomic times (WaitForSingleObject). - when Event is signaled or job is done, just return (use AfxEndThread() with AfxBeginThread() - MFC way) From main/any thread signal the event, when u want to stop the thread safely. To brutally kill the thread use: TerminateThread() Refer to samples in codeproject.com OR codeguru.com. Hth, Ramu

              Z Offline
              Z Offline
              zecodela
              wrote on last edited by
              #6

              Ramu, thank you! your information is so useful. currently, i am using a TerminateThread() to kill a thread. due to some reasons, i need to restart the threads few mins once. after few days running, it failed to to create thread with AfxBeginThread(). i doubted that related to using TerminateThread() to kill a thread. so, i am trying other methods. anyway, your information is useful and let me check with it! thanks, jim

              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