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. Safely close UI threads when program exit

Safely close UI threads when program exit

Scheduled Pinned Locked Moved C / C++ / MFC
designhelptutorialquestion
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.
  • G Offline
    G Offline
    GameProfessor
    wrote on last edited by
    #1

    hi, I have a list of UI threads that need to be close and clean up properly when user click "Exit" in the main GUI. How to do it? Here's what i've tried: CFrameWnd::OnClose() { for (i=0;i < my_number_of_thread; i++) { pThead[i]->EndThreadSafely(); } ClearThreadList(); } But my application crash in the end, debugging show an error at the AfxEndThread() that I call at the end of CMyThread::EndThreadSafely()

    R T 2 Replies Last reply
    0
    • G GameProfessor

      hi, I have a list of UI threads that need to be close and clean up properly when user click "Exit" in the main GUI. How to do it? Here's what i've tried: CFrameWnd::OnClose() { for (i=0;i < my_number_of_thread; i++) { pThead[i]->EndThreadSafely(); } ClearThreadList(); } But my application crash in the end, debugging show an error at the AfxEndThread() that I call at the end of CMyThread::EndThreadSafely()

      R Offline
      R Offline
      Roger Stoltz
      wrote on last edited by
      #2

      You end UI-threads by posting a WM_QUIT message to the thread. After you've posted the message you may wait for the thread to terminate by waiting on thread handle with e.g. ::WaitForSingleObject() in your main thread. Avoid AfxEndThread(), simply let the thread exit from it's controlling function which is the message pump in the UI-thread case. For more info read here[^] and here[^].


      "It's supposed to be hard, otherwise anybody could do it!" - selfquote
      "High speed never compensates for wrong direction!" - unknown

      1 Reply Last reply
      0
      • G GameProfessor

        hi, I have a list of UI threads that need to be close and clean up properly when user click "Exit" in the main GUI. How to do it? Here's what i've tried: CFrameWnd::OnClose() { for (i=0;i < my_number_of_thread; i++) { pThead[i]->EndThreadSafely(); } ClearThreadList(); } But my application crash in the end, debugging show an error at the AfxEndThread() that I call at the end of CMyThread::EndThreadSafely()

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        set CWinThread::m_bAutoDelete member to true!

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

        cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief and You

        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