Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart WPF application after click-once update (start the new version)

Tags:

How to restart WPF application after it has been updated using click-once, i need to start the new version!

like image 382
Sawan Avatar asked Mar 13 '11 19:03

Sawan


2 Answers

There are a few ways but most don't work correctly, they end up reopening the old version.

It's going to sound crazy that WPF doesn't have a proper way to handle it (#fixwpf), but you'll need to reference System.Windows.Forms.dll and call System.Windows.Forms.Application.Restart();

A quick search found Rob Relyea's post about the same thing (XAML, WPF Microsoft Guy) http://robrelyea.wordpress.com/2007/07/24/application-restart-for-wpf/

like image 160
GoldenTao Avatar answered Oct 05 '22 12:10

GoldenTao


It isn't necessary to include the winforms assembly just for this, that seems like overkill.

You can do the same thing that winforms does behind the scenes in it's restart method. After the Update Has been applied:

String ApplicationEntryPoint = ApplicationDeployment.CurrentDeployment.UpdatedApplicationFullName;  Process.Start(ApplicationEntryPoint);  //shutdown current instance here 

This Will Start the New Version Of Your Application With the proper ClickOnce initialization.

like image 39
Michael Kniffen Avatar answered Oct 05 '22 12:10

Michael Kniffen