Possible Duplicate:
Why is Application.Restart() not reliable?
I pulled the code straight from MSDN. This updates my application, but Restart()
does not work. The application shuts down, but it does not restart.
I added a MenuItem
to my Form
to validate that Restart()
works at all:
private void restartToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Restart();
}
This will restart the application (of course, it performs no updates and is user initiated, so it is fairly useless).
I have nothing else going on with this application. No event handlers for the Form on shutdown, nothing. This is the most basic Windows Forms application I could build (it just displays a resource JPEG in an ImagePanel
).
Why does Restart()
not work here?
Is your application Windows Forms or WPF? Because Application.Restart
only exists in the Windows Forms Application
object (System.Windows.Forms.Application) and is not supported by applications running under the WPF Application
(System.Windows.Applications). You can still call it, but as the application context is different, it doesn't work.
If you are using a Mutex, or something of the like to ensure only one instance of the application is running at a time, that be causing this issue.
Try wrapping it with a BeginInvoke just in case it's not on the main STA thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With