how to determine if app has crashed?


using vb2005, im developing an application. i would like to determine if the application has crashed, so that next time user starts it up i could show a custom message and course of action if it has. what's the best way to go about this?

LVL 13
Who is Participating?
neilpriceConnect With a Mentor Commented:
A good starting point for information is here:
Also see this link for logging unhandled exceptions:

This is an example program for you that shows reading and writing to/from an event log

If you're still stuck after looking at this let me know, just been a little busy since I last answered sorry!
Hope this helps,
You could try having a log file you write to regularly at different stages of the program.  When your application closes it saves a "successful close" as the last message to the log file.  When the application runs if the last message isn't "succesful close" you can then display the last succesful action logged.

newyuppieAuthor Commented:
if i use My.Application.Log to write log, does the log file rewrite itself when i restart the app? how would i implement a read on that log?
thanks for the answer
thebatdudeConnect With a Mentor Commented:
I'll let neilprice provide the code to read/write to Application.log, but let me provide you with some wrap around code so you can actually detect and adequately log a crash within your application.

     Public Sub Main()
        'Read From LOG or File or Registry to see if you previously crashed
        'Take Desired Action (also clear the log, file or registry key)

        MainForm = Nothing
        MainForm = New FormMain

            'Run your application
            'Clear the log, file or registry key indicating a crash has occurred because
            ' the application has shut  down normally.
        Catch ex As Exception
            'This code will trigger if the application crashes.
            MsgBox("The application has crashed.  The error was:  " & ex.ToString, MsgBoxStyle.Critical, "Unhandled Application Exception")
            'Write to log, file, or registry indicating a crash has occurred.
            Dim Answer As MsgBoxResult = MsgBox("Instability has been detected in the running application and will now be terminated to prevent further cascading errors." & vbCrLf & vbCrLf & "Do you want to restart the application?", MsgBoxStyle.Critical Or MsgBoxStyle.YesNo, "Application Instability Detected")
            If Answer = MsgBoxResult.Yes Then GoTo Restart Else System.Windows.Forms.Application.Exit()
        End Try
    End Function
newyuppieAuthor Commented:
thank you both for the help. i will have to study the links and code for a while so ill give you the points for helping. ill open other questions if i still have problems.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.