2

I have a multi thread MFC application. When I close the application during some operation, the application won't exit completely. I tried break all option in debug mode and found that the control is at AfxinternalPumpMessage in thredcore.cpp. I was not able to locate where in my code the wait is happening.

Is there any other way to locate the exact location in code where the wait happens. I am using VS2010.

CodeRider
  • 1,750
  • 6
  • 18
  • 34
  • 2
    How are you "closing the application during some operation". Please understand that point is *crucial* to understanding why your application is not exiting correctly, and you should include that detail in your question. – Jonathon Reinhart Jul 04 '13 at 04:47
  • You should be able to work it out by seeing which threads are still active (or conversely, which threads have exited). If you're still lost, you can [name your threads](http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx). If they are auto-deleted, you can put log messages into the constructor and destructor to help work out who is not behaving. – paddy Jul 04 '13 at 04:49
  • 1
    You can also call [ExitProcess](http://msdn.microsoft.com/en-us/library/windows/desktop/ms682658%28v=vs.85%29.aspx) to terminate the program. – paulsm4 Jul 04 '13 at 04:49
  • The operation am doing is adjusting brightness of image. Actually I need to know any tool for locating such errors. – CodeRider Jul 04 '13 at 04:51
  • @CodeRider *how* are you closing the application? – Jonathon Reinhart Jul 04 '13 at 04:54
  • AfxGetmainWnd()->PostMessage( WM_CLOSE ); – CodeRider Jul 04 '13 at 05:10
  • @paulsm4 if I call ExitProcess will all the threads exit normally. Should I consider any other aspects like memory leaks before calling it. – CodeRider Jul 04 '13 at 05:15
  • I used ExitProcess. Now the application exits normally in release mode. But in debug mode, on exiting a dialog box appears saying application triggered a breakpoint. – CodeRider Jul 04 '13 at 05:19
  • "ExitProcess" is drastic :) But it *will* kill all your threads (as you noticed), and it will also free all resources. So no, it will *not* introduce a memory or a resource leak. PS: AfxinternalPumpMessage is the MFC wrapper around Windows Main Event Loop. You might also be interested in this link: http://stackoverflow.com/questions/976012/diagnosing-an-app-that-fails-to-halt – paulsm4 Jul 04 '13 at 06:16
  • @paulsm4: No, `ExitProcess` will NOT free all resources. In fact, it won't free any resources at all. OS cleanup will then free any OS-related resource, including memory, but e.g. temporary files are not cleaned up. Calling `exit()` will clean up some temp files, but C++ dtors don't run. – MSalters Jul 04 '13 at 10:05
  • Exit process may not terminate all the thread correctly. See the bottom of the API doc for more info. – Dan G Aug 15 '17 at 20:05

0 Answers0