Search code examples
c#wpfrestart

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?


Solution

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