These proposed solutions may work, but as another commenter has mentioned, they feel kind of like a quick hack. Another way of doing this which feels a little cleaner is to run a batch file which includes a delay (e.g. 5 seconds) to wait for the current (closing) application to terminate.
This prevents the two application instances from being open at the same time. In my case its invalid for two application instances to be open at the same time - I'm using a mutex to ensure there is only one application open - due to the application using some hardware resources.
Example windows batch file ("restart.bat"):
sleep 5
start "" "C:\Dev\MyApplication.exe"
And in the WPF application, add this code:
// Launch the restart batch file
Process.Start(@"C:\Dev\restart.bat");
// Close the current application
Application.Current.MainWindow.Close();
In my program I have a mutex to ensure only one instance of the application running on a computer. This was causing the newly started application to not start because the mutex had not been release in a timely fashion. As a result I put a value into Properties.Settings that indicates that the application is restarting. Before calling Application.Restart() the Properties.Settings value is set to true. In Program.Main() I also added a check for that specific property.settings value so that when true it is reset to false and there is a Thread.Sleep(3000);
In your program you may have the logic:
if (ShouldRestartApp)
{
Properties.Settings.Default.IsRestarting = true;
Properties.Settings.Default.Save();
Application.Restart();
}