Juliano Oliveira
Juliano Oliveira

Reputation: 928

Restarting WPF C# don't kill previous process

I'm developing an application using WPF on C#, and in some occasions i need to restart the application, the problem occurs when i restart the application but the old process continues to run ( i can see this on task manager). How can i restart the application killing the current process. Below my code:

function Restart

private void restart()
{
    this.Dispatcher.Invoke((Action)(() =>
    {
        System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
        Application.Current.Shutdown();
    }));
}

Upvotes: 1

Views: 427

Answers (1)

StepUp
StepUp

Reputation: 38199

This method terminates this process and returns an exit code to the operating system.

Environment.Exit(0)

You can set exit code parameter to indicate whether the application is closed with an error(msdn article).

Upvotes: 2

Related Questions