locked
Application Stopped Working after Shutdown Event

    Question

  • I have an issue that I need guidance on please.

    Visual Studio 2008, VB.NET, .NET Framework 3.5. Development Machine Vista Business. Problem occurs in Vista, Windows 7. It does not occur on XP.

    Others involved: Bennet-Tec Tlist tree control, Farpoint Spread for Winforms 5 spreadsheet control, ADO.NET with Access Database.

    Message issued:

    (Application Name) has stopped working.

    A problem caused the program to stop working correctly. Please close the program.

    [Close the Program button].

    With my capabilities, I have narrowed the location of the (crash?, unhandled exception?) to somewhere after the application shutdown event and before the firing of the Finalize event with the following ApplicationEvents code:

    Namespace My

       ' The following events are available for MyApplication:
       '
       ' Startup: Raised when the application starts, before the startup form is created.
       ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
       ' UnhandledException: Raised if the application encounters an unhandled exception.
       ' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
       ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
       Partial Friend Class MyApplication

          Private Sub MyApplication_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
             AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException
             MsgBox("Shutdown")
          End Sub

          Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup

             ' Add the event handler for handling non-UI thread exceptions to the event.  
             AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf CurrentDomain_UnhandledException

          End Sub

          Private Shared Sub CurrentDomain_UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
             MsgBox("UnhandledException caught")
          End Sub

          Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
             MsgBox("Bingo")
          End Sub

          Protected Overrides Sub Finalize()
             MsgBox("Before Mybase.Finalize")
             MyBase.Finalize()
             MsgBox("After Mybase.Finalize")
          End Sub

       End Class

    End Namespace

    This problem is intermittent. It does not happen every time but it does happen with frequency.

    None of the handlers within above catch it.

    I do not have the wherewithal in remote debuggers, ProcDump, WinDbg, etc. as was mentioned in a similar thread:

    http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/3b17b3b2-f703-46ee-b7b2-04788987d0b9

    Is there anything I can do in application code to catch and handle this?

    What happens between the Shutdown and Finalize events?


    JP Brazill

    Thursday, February 16, 2012 4:40 PM

All replies

  • First thing I wonder is why you get this message while running in the IDE. The debugger should handle any unhandled (second chance) exception. Do you get a "first chance" exception the output window? Can you post a screenshot if the error occurs? I need a picture of this situation.

    Armin

    Thursday, February 16, 2012 10:18 PM
  • Armin,

    Actually the message I described above is when running the executable on Windows 7.

    It varies when running on Vista:

    (Application Name) has stopped working.

    Windows is checking for a solution to the problem...

    [Progress Bar]

    [Cancel Button]

    followed by another message box if the cancel button is not pressed:

    (Application Name) has stopped working.

    A problem caused the program to stop working correctly. Windows will

    close the program and notify you if a solution is available.

    [Debug button] [Close Program button]

    pressing Debug is fruitless (after choosing either new or existing VS2008, yields a message about a lack of symbols or something...) 

    I do get a similar message when running in the IDE that simply says:

    vshost32.exe has stopped working

    A problem caused the program to stop working correctly. Windows will

    close the program and notify you if a solution is available

    [Debug button] [Close program button]


    JP Brazill


    Friday, February 17, 2012 2:42 PM
  • I do get a similar message when running in the IDE that simply says:

    vshost32.exe has stopped working

    A problem caused the program to stop working correctly. Windows will

    close the program and notify you if a solution is available

    [Debug button] [Close program button]

    Thx for clarifying. Also for others, because it seems I'm not of much help here. I remember I had problems debugging on Win7 at the beginning, but I'm unable to recall exactly what it was.

    ......... Here it is (only the very first paragraph is of interest): 
    https://groups.google.com/group/microsoft.public.dotnet.languages.vb/browse_frm/thread/dd6ddeea91a91c18/f4fe8d86a6fbf925?tvc=1#f4fe8d86a6fbf925

    However, I'm not sure if it's related to your situation.


    Armin

    Friday, February 17, 2012 3:41 PM
  • Hi John,

    May I know when did you encounter the error dialog ("application stop working")? when start the application, or close the application?

    As Armin mentioned, if you do not want to capture dump or debugging using WinDbg, you can choose Visual Studio, run your application from the IDE by pressing F5 shortcut key, once the 2nd chance exception happen, Visual Studio will break the debuggee process and tell you what happened.


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.

    Regards,
    Eric Yang
    Microsoft Online Community Support


    Friday, February 24, 2012 2:48 AM