4

Can an app written with .net Compact Framework restart itself?

What are some of the common patterns to achieve this? I would like to have a self-updating application that restarts itself if update was done.

Of course, I could have 2 .exe: one that updates and the actual app, but I would rather just have one.

sarsnake
  • 26,667
  • 58
  • 180
  • 286
  • 3
    If you can have two instances of the app running at the same time, just have the app launch itself and then exit. – Chris Eberle May 25 '11 at 22:48

1 Answers1

4

Absolutely. It's actually way easier to do than on the desktop. If you're using the SDF, use this:

var thisName = Assembly.GetExecutingAssembly().GetName().CodeBase;
var time = DateTime.Now.AddSeconds(11);
Notify.RunAppAtTime(thisName, time);

If you want to do it manually, you'd p/invoke CeRunAppAtTime.

Note that you must have a launch time of > 10 (not >= 10) seconds in the future or the "launch will happen immediately (an artifact of how the default notification setup is set in the kernel).

ctacke
  • 66,480
  • 18
  • 94
  • 155
  • Should this necessarily be placed inside Program.cs file? I am placing this inside the Form code behind and nothing happens. Also, can I pass arguments to my app using this code? If possible, how? Thank you! – sarsnake Aug 17 '11 at 20:07
  • It should work from anywhere, but in any case you must shut the currently running app down after you make the call. – ctacke Aug 17 '11 at 20:25
  • And no, you can't pass any arguments to the other app instance. – ctacke Aug 17 '11 at 20:25
  • thank you! I just verified it and that seemed to be the case - the current app was still running. once closed, it restarted. – sarsnake Aug 19 '11 at 19:47
  • @ctacke So this will restart the application after 11 secs the current application shut down-right.Application.Exit() should comes after the restart code or before the restart code.Please clarify. – Royal Jun 22 '14 at 15:35
  • Yes, you would exit the app right after calling this and your app will re-start in 11 seconds. – ctacke Jun 23 '14 at 01:10
  • @ctacke I am using this in compact framework 3.5. and I tried in emulator but application is not getting restarted.I am not getting any exception also.Did restart functionality work in emulator,Thanks. – Royal Jun 23 '14 at 08:59