Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Application.Restart' not working in ClickOnce deployed application [duplicate]

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?

like image 563
Chris Holmes Avatar asked Apr 08 '09 16:04

Chris Holmes


3 Answers

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.

like image 196
Greg Bacchus Avatar answered Nov 17 '22 06:11

Greg Bacchus


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.

like image 25
Timothy Carter Avatar answered Nov 17 '22 06:11

Timothy Carter


Try wrapping it with a BeginInvoke just in case it's not on the main STA thread.

like image 1
Brandon Grossutti Avatar answered Nov 17 '22 07:11

Brandon Grossutti