Solved

how to determine if app has crashed?

Posted on 2006-06-14
5
232 Views
Last Modified: 2012-06-21
hi,

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?

thanks
0
Comment
Question by:newyuppie
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:neilprice
ID: 16908669
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.

Neil
0
 
LVL 13

Author Comment

by:newyuppie
ID: 16912377
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
0
 
LVL 1

Assisted Solution

by:thebatdude
thebatdude earned 250 total points
ID: 16913153
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()
Restart:
        '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

        Try
            'Run your application
            System.Windows.Forms.Application.Run(MainForm)
            '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
0
 
LVL 6

Accepted Solution

by:
neilprice earned 250 total points
ID: 16913838
A good starting point for information is here: http://msdn2.microsoft.com/en-us/5049kcd2.aspx
Also see this link for logging unhandled exceptions: http://msdn2.microsoft.com/en-us/3a02k5s0.aspx

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

http://www.thescarms.com/dotnet/EventLog.asp

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,
Neil
0
 
LVL 13

Author Comment

by:newyuppie
ID: 16928277
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.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now