0

I read many forums and links like:

How do I restart my C# WinForm Application?

but all this are for windows not for mobile. How can i restart my mobile application when i catch unhandled exception. Now app is closed when i catch unhandled exception but i do not want to close it so i want to restart it.

This not working:

ProcessStartInfo s = new ProcessStartInfo();
            s.FileName = Assembly.GetExecutingAssembly().GetName().CodeBase;
            s.UseShellExecute = false;
            Process.Start(s);

i am uisng windows mobile 6.1 and CF 3.5

2 Answers 2

4

WinMo has a mechanism baked in to prevent multiple instances of an app from running, so calling yourself with the Process class will simply launch an instance that the shell terminates. You have to work around that, P/Invoke CeRunAppAtTime or create a separate watchdog process that makes sure your app process is always running, launching a new instance if it detects it is ever gone.. Be forewarned that CeRunAppAtTime can't schedule an app for less than 11 seconds into the future, so there will be a delay.

0
2

You shouldn't. The best approach is to prevent that exception with fixing the bug that causes it in the first place.

But if you really, really, really need to restart your application for any other reason than crashes, then you can start another process in the background along with your application that watches if the application is still running and starts it with Process.Start() again if it doesn't.

(If your application is set to run automatically on the device and your device supports it, -which is not very likely since it's a Windows CE thing, but why not- you can also create Watchdog timers to restart the entire device if needed.)

But restarting an application all the time (let's say once a day) ruins the user experience and also the user's trust. So you should fix the exception instead.

2
  • 1
    And yes, I saw your other question about the crash, and if you could clarify there a little what kind of exception do you actually catch and under what circumstances is it thrown than maybe somebody would be able to help with that part.
    – ytg
    Oct 19, 2011 at 10:35
  • I never want to close my app. I want to open Login form when i get unhandled exception. Network is down,... Oct 19, 2011 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.