views:

1328

answers:

6

I pulled the code straight from MSDN: http://msdn.microsoft.com/en-us/library/ms404263.aspx

This updates my application, but Restart() does not work. The application shuts down, but 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, performs no updates and is user initiated, so 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 WinForm app I could build (just displays a resource JPG in an ImagePanel).

Why does Restart() not work here?

A: 

One hour without any answer, seems like i'm going to risk with it.

Try to raise a new process, maybe that can workaround it.

Process.Start(Application.ExecutablePath);
Jhonny D. Cano -Leftware-
A: 

Are you sure that you're calling Application.Restart from the main form? If you call a form with .ShowDialog and then from that form call Application.Restart, it won't work because the .ShowDialog causes the dialog form to run on a separate thread.

Matt Hanson
There is only the main form. I am working with as simple of an app as possible to eliminate errors.
Chris Holmes
+1  A: 

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.

Timothy Carter
A: 

try wrapping it with a begininvoke just in case its not on the main sta thread

Brandon Grossutti
A: 

See this other SO question.

uzbones
+3  A: 

Is your application WinForms or WPF? Because Application.Restart only exists in the WinForms 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.

Greg Bacchus
Good point Greg.
JimDel