0

Consider an ordinary Windows 8+ app. Call the app Teste.

This is running on a captive computer which has no other purpose and there are no security concerns, any Windows settings can be used.

I want Teste to be able to: quit itself and then indeed launch itself again.

Exactly as if a user happened to quit the app, and then launch it again.


(Note ... a handy workaround in some situations if you have this problem - just have the app restart the whole machine ([how-to][1]), and have the app launch on startup of the box just using startup items in Windows. {So, Windows+R, shell:Common Startup, add a shortcut.} )

Fattie
  • 27,874
  • 70
  • 431
  • 719

1 Answers1

-1

I actually still think my original answer applies, but SO's comment system is frustrating me, so I'm just going to try again.

Is it possible for an application to do anything after it has quit? No. And that obviously includes starting itself.

Can an application request that the operating system (or another process) restart it? Yes, assuming the operating system supports it (see Application.Restart()) but this may not reliably restart your application (it is dependent on the operating system and the first results you'll find from Google indicate Application.Restart() is not dependable). Obviously it must issue this request before it quits (or depend on another process to do so afterward). Whatever it depends on to actually do this may simply refuse the request.

My original answer was attempting to find the best work-around (real world solution) for your problem. There are probably at least a dozen, but none that do not depend on some sort of external process, whether that's the operating system, a service within the operating system or the boot loader. In a Windows environment, the best thing you could depend on, in my opinion, is a service, because you can control exactly how it functions.

Shaun
  • 140
  • 6
  • Application.Restart() is concrete information for C# with the .NET Framework. I suspect you're looking for a Unity-specific answer (with which I do not have experience) and not a language-specific answer. – Shaun Apr 11 '15 at 07:42
  • This may help you, but I'm honestly just guessing as I don't know unity: http://answers.unity3d.com/questions/11816/how-can-i-restart-the-game-fast.html - seems to make some assumptions, and it is definitely not a full application restart. – Shaun Apr 11 '15 at 07:50
  • You could also start a new process with instructions to wait a specific time before starting a third process which is actually your first application, and close your first process after starting the second, and then close the second as soon as it has started the third. Like I said, at least a dozen workarounds, but they all depend on keeping a process running, somehow. – Shaun Apr 11 '15 at 07:53
  • hi Shaun. Ah, sorry I didn't notice the mention of **Application.Restart()** in your answer. Fantastic. I'll investigate that, didn't know about it! (I have little knowledge or interest in .Net, hence the point of the question.) – Fattie Apr 11 '15 at 08:41
  • PS, it tends to be a staggering waste of time to "suspect" things on these sites. No connection to unity. Sorry I mentioned it in passing. (Tip to self - mention nothing other than core issues right?) Also FYI the incredible amount of very general beginner information you give ("You could also start a new process..." etc) is very often un-useful here. I wanted to know what it says in the title. Thanks again. Suggest you change your answer to just "What about Application.Restart()" :) – Fattie Apr 11 '15 at 08:45
  • Actually I set 30 minutes aside to wade through the rest of the answer :) and I see you explain Application.Restart() is apparently not reliable. Thanks also for that great tip, I'll investigate..... Hopefully someone will additionally answer who has specific exact technical knowledge about Application.Restart(), cheers – Fattie Apr 11 '15 at 08:47
  • Application.Restart() is specifically addressed in other StackOverflow answers. It may very well be the solution you seek. Please see http://stackoverflow.com/questions/779405/how-do-i-restart-my-c-sharp-winform-application which links to a question about it's reliability. If you're not doing anything that blocks it, it could work for your situation. You're trying to do something that is a little tricky and has some caveats for any given situation, so there's just not a blanket answer (afaik) without more information. I recommend testing Application.Restart(). – Shaun Apr 11 '15 at 09:10
  • Also, my apologies if it seems like I'm just trying to find an answer to fit the question - I'd much rather help you find a solution to your problem than answer a theoretical question. But there's a lot of things at play that can interfere in something like this. There ***is*** a way to do what you want to do, but which way is the right one for you is not necessarily something I can tell from the limited information I have. – Shaun Apr 11 '15 at 09:14
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/74995/discussion-between-shaun-and-joe-blow). – Shaun Apr 11 '15 at 09:21