C#.codebox 9
WPF – How to restart my application?
Unfortunately, to date, WPF does not have a Restart() function line in WinForms so one way to do this is by using…WinForms.
1 | System.Windows.Forms.Application.Restart(); |
However, after running this code our application will not exit on it’s own, even though a new instance of the application is being created. Therefore, we must close it manually…for example by doing:
1 | Application.Current.Shutdown(); |
If you don’t want to use WinForms with your application you can do something like:
1 2 3 4 5 | //things to do before closing // ... //Restart System.Diagnostics.Process.Start(Application.ResourceAssembly.Location); Application.Current.Shutdown(); |
Where we create a new instance of our application, by using Process.Start, and immediately close the current one.
