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 close a thread?

how to close a thread?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 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.
  • D Offline
    D Offline
    doneirik
    wrote on last edited by
    #1

    I have a second thread in my application, created like this: Thread* secondThread; ThreadStart* second = new ThreadStart(this,my_method); secondThread = new Thread(second); secondThread->Start(); This thread does not close when I close down the application. I tried with "Abort". I guess I need some try-catch, but sot sure how to use it... tried with this in the generated dispose method... try{ secondThread->Abort(); } catch(char* szException){} components->Dispose; ...this didn´t work. Any suggestions as to how to close the thread. (doesn´t need to be "proffesional" as I´m just building a test app with really dirty coding...) Also...is the creation of the thread the "best" way to create a thread (I have seen a couple of different solution, though this was the one that I found easier imediately. regards, doneirik

    A D 2 Replies Last reply
    0
    • D doneirik

      I have a second thread in my application, created like this: Thread* secondThread; ThreadStart* second = new ThreadStart(this,my_method); secondThread = new Thread(second); secondThread->Start(); This thread does not close when I close down the application. I tried with "Abort". I guess I need some try-catch, but sot sure how to use it... tried with this in the generated dispose method... try{ secondThread->Abort(); } catch(char* szException){} components->Dispose; ...this didn´t work. Any suggestions as to how to close the thread. (doesn´t need to be "proffesional" as I´m just building a test app with really dirty coding...) Also...is the creation of the thread the "best" way to create a thread (I have seen a couple of different solution, though this was the one that I found easier imediately. regards, doneirik

      A Offline
      A Offline
      Abyss
      wrote on last edited by
      #2

      Try ExitThread or TerminateThread but read the doc before you use it!

      1 Reply Last reply
      0
      • D doneirik

        I have a second thread in my application, created like this: Thread* secondThread; ThreadStart* second = new ThreadStart(this,my_method); secondThread = new Thread(second); secondThread->Start(); This thread does not close when I close down the application. I tried with "Abort". I guess I need some try-catch, but sot sure how to use it... tried with this in the generated dispose method... try{ secondThread->Abort(); } catch(char* szException){} components->Dispose; ...this didn´t work. Any suggestions as to how to close the thread. (doesn´t need to be "proffesional" as I´m just building a test app with really dirty coding...) Also...is the creation of the thread the "best" way to create a thread (I have seen a couple of different solution, though this was the one that I found easier imediately. regards, doneirik

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        See here.


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        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