Application Disaster Recovery

What is the best way (possibly a standard solution) to create disaster recovery in my application so that it can automatically restart if there is any failure.

Tpx.

+6
c # desktop-application
source share
3 answers

Here you have several options.

The first (and best) is to add some type of global error handling that will catch any otherwise uncaught exceptions and handle them correctly. Along these lines, you should start adding the appropriate specific exception handling to your code base. Keep in mind that stack overflows and some security and memory exceptions will occur regardless of any global processing.

The second option is to have a monitoring service that simply checks if the current application is running. If this is not the case, then forcefully destroy the existing application and restart the new instance.

The third option is to separate your application from two applications. An external container-type application that simply runs another process. The container application will not have a user interface, but it will start the main process and look at it (as option 2 above). I saw that it is used in various "modular" applications.

The bottom line is that the only real way to do this is to have 2 applications: one for monitoring, the other for creating a user interface and everything else.

+6
source share

As a rule, itโ€™s better not to do this, there is nothing wonderful in a process that constantly starts and immediately crashes again when the user looks helplessly at the slaughterhouse. But I can only pass you the bullets, aiming the gun on the leg, it is up to you. You will need the following code:

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); } } 

Remember that I applied the shortcut in the command line arguments. They must be specified if they contain a path to a file that contains spaces. Do not use shortcuts to code that you must put in the ellipsis.

+10
source share

Put your persistent state in what supports transactions. For example. Database (sqlite) or if needs are not too complicated, use a copy when writing (write changes to a new file and only if it was successfully discarded the old file)

These suggestions are very general.

0
source share

All Articles