How can I restart an application from within it?
How can my application restart itself? [duplicate]
Asked Answered
It's a bit more complex than you would think: #779905 –
Maus
It's extremely rare that you application should ever need to restart itself. The only conceivable scenario is to automatically install updates, but the most logical way to handle that is with a helper application that downloads the updates and installs them at the next launch. The same model used by popular apps like Google Chrome and Mozilla Firefox, not only to solve this issue but also because it's far more user-friendly. –
Oddball
possible duplicate of How do I restart my C# WinForm Application?, also see What's the best way for a .NET windows forms application to update itself? –
Oddball
One possible reason to restart your app (that I have used previously) could be in a ClickOnce deployment, where you check to see if an update is available in your code, you can then handle the actual update by setting the app to check for updates before it runs and restart it so that the update is done for you. –
Antagonist
It makes sense if it's a server application and it needs to run constantly, 24/7. Bugs and exceptions are unavoidable in every program, but we don't want our server to just die if something unexpected happen. Yes, most of the time we can handle exceptions, but some exceptions mean we don't have the data required to continue, the state is unstable, we could break things if we continued, so the restart is the most reasonable solution. –
Gobi
Application.Restart is what you are looking for I think. I used this on one project and have to say that it worked fine for me - but other people seem to have run into issues with this.
Are you sure it doesn't provide the command line arguments again? The MSDN docs (that you linked) state that it will, and I've heard other people say the same, e.g over here –
Akanke
@Akanke - you are correct. I thought I had read that this wasn't the case. I will edit my answer accordingly. –
Antagonist
© 2022 - 2024 — McMap. All rights reserved.