What's the best way (standard solution maybe) to build crash recovery into my application so it can automatically restart on any kind of crash.
tnx.
Crash recovery is the process by which the database is moved back to a consistent and usable state. This is done by rolling back incomplete transactions and completing committed transactions that were still in memory when the crash occurred (Figure 1). Figure 1. Rolling back units of work (crash recovery)
What Are the Types of Recovery? There are three basic types of recovery: instance recovery, crash recovery, and media recovery. Oracle performs the first two types of recovery automatically at instance startup; only media recovery requires you to issue commands.
The log records in the log buffer and in the log file are used to undo the changes of the failed transaction in reverse order. System (crash) recovery is needed when the whole database (transaction) system fails, e.g., due to a hardware or software error.
It is in general better not to do this, there's nothing pretty about a process that constantly starts and immediately crashes again with the user helplessly looking at the carnage. But I can only hand you the bullets, aiming the gun at your foot is up to you. You'll need code like this:
static void Main(string[] args) {
AppDomain.CurrentDomain.UnhandledException += ReportAndRestart;
// etc..
}
static void ReportAndRestart(object sender, UnhandledExceptionEventArgs e) {
string info = e.ExceptionObject.ToString();
// Log or display info
//...
// Let the user know you're restarting
//...
// And restart:
System.Diagnostics.Process.Start(
System.Reflection.Assembly.GetEntryAssembly().Location,
string.Join(" ", Environment.GetCommandLineArgs()));
Environment.Exit(1);
}
}
Beware that I took a shortcut on the command line arguments. They should be quoted if they contain a path to a file that contains spaces. Don't take shortcuts on the code you're supposed to put in the ellipsis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With