How to Restart a Wpf Application

How do I restart a WPF application?

I found this:
It works.
But.
Is there any better way?

System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
Application.Current.Shutdown();

WPF application restart

You should try to get the process rather than the assembly, which can return a .dll.

Restart the current application:

var currentExecutablePath = Process.GetCurrentProcess().MainModule.FileName;
Process.Start(currentExecutablePath);
Application.Current.Shutdown();

Restart application using C#

I don't think there's a direct method in WPF like there is in WinForms. However, you could use methods from the Windowns.Form namespace like this: (You might need to add a reference to the System.Windows.Form assembly)

System.Windows.Forms.Application.Restart();

System.Windows.Application.Current.Shutdown();

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

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/



Related Topics



Leave a reply



Submit