How to restart NETMF C # firmware on error?

I have a small, long-running, built-in, NETMF program that stops for unknown reasons (see How can we get rid of a long-term NETMF program that stops in production? ). As a workaround, I would like it to restart automatically with an error. I believe a try-catch block can do this. How? Is it possible? Is there a better approach?

public class Program
{
    private static Timer timer;      
    public static void Main()
    {
        Program p = new Program();

        Program.timer = 
            new Timer(this.TimerCallback_DoSomething, new object(), 0, 1000);

        Thread.Sleep(Timeout.Infinite);
    }

    private void TimerCallback_DoSomething(object stateInfo)
    {
        // do something
    }
}
+4
source share
5 answers

try/catch, , . , .

, , . :

Process p = new Process();
p.Exited += StartItAgain;
// other setup
p.Start();
+1

, , , , , Windows .

+1

Pantelis .Net, , , , , UnhandledException .

I don’t think that restarting the application will solve your problem, it will hide your problem, but if you like to do this, there are many ways to do this:

  • Try to start the process again.
  • In an UnhandledException, launch the application.
  • Error code when an exception occurs and if there is an application, the Event checks the error code, and if the error code is not 0, restart the application.
+1
source

Source: https://habr.com/ru/post/1535629/


All Articles