CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: App crash

  1. #1
    Join Date
    Aug 2019
    Posts
    72

    App crash

    VS2015 mfc app with a button click launches a thread. After thread exists and dialog's X on top right is clicked on, it closes and re-launches. The event viewer shows the event name APPCRASH. problem signature item 4 points to mfc140.dll.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: App crash

    Quote Originally Posted by @EE@ View Post
    After thread exists ...
    Did you mean "exists" or "exits"?
    Victor Nijegorodov

  3. #3
    Join Date
    Aug 2019
    Posts
    72

    Re: App crash

    after thread exits. After all processing done. After X on the top right is clicked on to close the APP. After APP apparently closed, After a few seconds, it launches again on its own. checked the event viewer. Maybe a compatibility related between the DLL and APP?.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: App crash

    How do you start your thread?
    How does the thread exit?
    What DLL do you mean? Are you using some external DLL? Which one?

    PS. A peace of your actual code could be helpful to understand your problem.
    Victor Nijegorodov

  5. #5
    Join Date
    Aug 2019
    Posts
    72

    Re: App crash

    this is the way I start my thread and get going to the end.
    https://www.codeproject.com/Articles...d-to-terminate

  6. #6
    Join Date
    Aug 2019
    Posts
    72

    Re: App crash

    my application is multi tab application which uses tab tree control. The APPCRASH may not be related to start of the thread. I could not see any memory lean risk code. I use CREATE for each dialog in each tab.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: App crash

    Quote Originally Posted by @EE@ View Post
    my application is multi tab application which uses tab tree control. The APPCRASH may not be related to start of the thread. I could not see any memory lean risk code. I use CREATE for each dialog in each tab.
    How many threads are started in your application?
    Does the every tab dialog start the thread?
    How did you check whether all started threads successfully exit before closing your application?
    Victor Nijegorodov

  8. #8
    Join Date
    Aug 2019
    Posts
    72

    Re: App crash

    only one thread get started in one of the tabs by clicking on a button. the rest are regular buttons.

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: App crash

    Quote Originally Posted by @EE@ View Post
    my application is multi tab application which uses tab tree control. The APPCRASH may not be related to start of the thread. I could not see any memory lean risk code. I use CREATE for each dialog in each tab.
    And what about answering my other question?
    Quote Originally Posted by VictorN View Post
    How many threads are started in your application?
    Does the every tab dialog start the thread?
    How did you check whether all started threads successfully exit before closing your application?
    Victor Nijegorodov

  10. #10
    Join Date
    Aug 2019
    Posts
    72

    Re: App crash

    How many threads are started in your application?

    in one of the tabs only when a button is clicked on.

    Does the every tab dialog start the thread?

    click on a button

    How did you check whether all started threads successfully exit before closing your application?

    i follow something similar to this link:
    https://www.codeproject.com/Articles...d-to-terminate

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: App crash

    Quote Originally Posted by VictorN View Post
    ...
    How did you check whether all started threads successfully exit before closing your application?

    i follow something similar to this link:
    https://www.codeproject.com/Articles...d-to-terminate
    Your "something similar" means nothing until you will show your actual code.
    Victor Nijegorodov

  12. #12
    Join Date
    Aug 2019
    Posts
    72

    Re: App crash

    this is the code i use to check for thread exit.
    Code:
    void CMyDlg::OnBnClickedButton()
    {
    	m_pWinThread = AfxBeginThread(MyThreadFunc, (LPVOID)this);
    
    	DWORD ret;
    	do
    	{
    		ret = ::MsgWaitForMultipleObjects(1, &m_pWinThread->m_hThread, FALSE,
    			INFINITE, QS_ALLINPUT);
    		if (ret != WAIT_OBJECT_0)
    		{
    			if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    			{
    				TranslateMessage(&msg);
    				DispatchMessage(&msg);
    			}
    		}
    	} while ((ret != WAIT_OBJECT_0) && (ret != WAIT_FAILED));
    
    	AfxMeesageBox("Done");
    }

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: App crash

    Quote Originally Posted by @EE@ View Post
    this is the code i use to check for thread exit.
    However, I asked you about the code showing how exactly you implemented the thread's exit.
    And, BTW, do you create some handles within the thread that were not closed before exiting?
    Victor Nijegorodov

  14. #14
    Join Date
    Aug 2019
    Posts
    72

    Re: App crash

    the thread includes a series of steps till it returns. The first step is to initialize the library. I moved it out of the thread and seems to resolve it. Not 100% sure yet. Need to do more testing. Not sure why this would help if moved out of the thread function. I am passing 0 or NULL instead of this object.
    I do not create handles, no.

  15. #15
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: App crash

    1. How exactly does the thread exit? Note that the best way to exit for a worker thread is just to return from the thread procedure. If the thread has no idea about when it has to exit then the main thread has to notify it (usually by setting an Event) about it!

    2. What type of the library do you initialize within the thread? Does the library need to be "uninitialized" (or to be closed / cleaned up / ...)?
    Victor Nijegorodov

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured