ExampleWasTaken
ExampleWasTaken

Reputation: 43

WPF application restart

I have to restart an application. When I googled about it I found this and several others suggesting this code:

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

but all it did, was closing the application. I tried it within Visual Studio, and just executing the exe in the bin folder, but it always turned out the same. The project is a .NET Core WPF. Any additional ideas, or ideas what the problem could be?

Upvotes: 2

Views: 3479

Answers (1)

BionicCode
BionicCode

Reputation: 29028

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();

Upvotes: 13

Related Questions