views:

79

answers:

3

Hi

if my C# Windows mobile program crashed, How to make reset to this program ?

(automatic - without any user interference)

thank's in advance

+2  A: 

You would have to have another application that monitors your program and as soon as it finds out it has crashed, it then can restart that application.

tomlog
+1  A: 

I see 2 posible solutions 1) the way tomlog suggested with having 2 proccess monitor eatch other. (The bad way)
2) Make your application aware thats its crashing, and do something then ( You can proberbly not restart it, but perhaps start another application that will do it)

I would recommend using version 2 simply because mobile phones have limited resources and spawining a program that does nothing but check if another is running seems like bad practice, esp on a phone.

[MTAThread]
static void Main()
{
    AppDomain CurrentDomain = AppDomain.CurrentDomain;
    CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);

    Application.Run(new MainWindow());
}

static void OnUnhandledException(Object sender, UnhandledExceptionEventArgs e)
{
    Exception ex = (Exception)e.ExceptionObject;

}
EKS
A: 

i agree with EKS - handle critical exceptions and re-spawn the app when an unrecoverable situation occurs - be careful with infinite re-spawning loops though!

fusi