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

1

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.

Wharton answered 25/5, 2011 at 22:45 Comment(1)
If you can have two instances of the app running at the same time, just have the app launch itself and then exit.Craigcraighead
L
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).

Lippold answered 26/5, 2011 at 2:39 Comment(7)
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!Wharton
It should work from anywhere, but in any case you must shut the currently running app down after you make the call.Lippold
And no, you can't pass any arguments to the other app instance.Lippold
thank you! I just verified it and that seemed to be the case - the current app was still running. once closed, it restarted.Wharton
@Lippold 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.Euripides
Yes, you would exit the app right after calling this and your app will re-start in 11 seconds.Lippold
@Lippold 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.Euripides

© 2022 - 2024 — McMap. All rights reserved.