views:

921

answers:

3

hi

How I can reset my C# program ?

I want that my program will start again

in Windows mobile

thank's in advance

A: 

There is the Application.Restart method, but it doesn't look like it's supported on the Compact Framework. You could try:

Application.Exit();
Application.Run(new MyForm());
heavyd
Application.Exit() will result in a exit 0 code to the application... Application.Run(new MyForm()) doesn't work after...
Zanoni
Please reread to documentation... http://msdn.microsoft.com/en-us/library/ms157894.aspx "This method does not necessarily force the application to exit."
heavyd
A: 

Run:

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

And:

Application.Exit();
Zanoni
+1  A: 

One way is to P/Invoke (or use an existing wrapper) around the CeRunAppAtTime API, schedule your app to launch in a couple of seconds time, and exit. The SDF (www.opennetcf.org/sdf/) has a wrapper for this API.

Peter

-- Peter Foot Device Application Development MVP www.peterfoot.net | www.inthehand.com

From The Internet Archive ( http://web.archive.org/web/20071231144636/http://www.themssforum.com/Compact/application-restart/ ). (I gave up on figuring out why the url parser hates that link)

See CeRunAppAtTime on MSDN.

Unlike Zanoni's solution, this will not have two instances of your application running at the same time. It's much uglier, though.

Brian