How do I restart a WPF application?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
WPF does not provide a dedicated restart method because restarting is really a process-management task, not a UI feature. In practice, restarting means starting a new copy of the current executable and then shutting down the existing application cleanly.
The Basic Restart Pattern
A reliable restart flow has three steps:
- Find the current executable path.
- Launch a new process for that executable.
- Close the current application.
In current .NET versions, Environment.ProcessPath is the simplest way to locate the running executable.
You can call AppRestarter.Restart() from a menu command, a settings screen, or an update workflow.
Preserving Command-Line Arguments
Some desktop applications rely on startup arguments for mode selection, file opening, or diagnostics. If the current process was started with arguments, you may want the new process to inherit them.
This is especially useful if your application supports file associations or launches into specific workspaces.
Save State Before Restarting
Many restart flows exist because settings only take effect after startup. When that is the case, save state before launching the replacement process.
Without the save step, the application restarts correctly but the requested configuration never takes effect.
Restarting from Background Work
If a background task discovers that a restart is required, finish the process launch and shutdown on the UI thread. WPF application lifetime is UI-centered, so doing the final shutdown from the dispatcher is safer.
This keeps the restart aligned with normal WPF threading rules.
Single-Instance Applications Need Extra Care
If your app uses a mutex or another single-instance guard, the new process can start before the old one fully exits. The result is a failed restart where the replacement instance immediately quits.
There are a few ways to handle that:
- release the single-instance lock before shutdown
- delay the relaunch slightly
- use a bootstrapper or updater process to perform the handoff
A helper process is common in auto-update systems because it can wait until the main app exits, replace files if necessary, and then start the new version cleanly.
Why the Order Matters
Always start the new process before shutting down the current one. If you close first, the restart code may never run to completion, especially if shutdown triggers cleanup logic or window teardown that stops later instructions.
The start-then-shutdown order also makes debugging easier because you can confirm that Process.Start succeeded before the app exits.
Common Pitfalls
The most common mistake is shutting down before starting the replacement process. That can leave the user with a closed application and no restart.
Another issue is forgetting to save settings, temporary files, or unsent work before restart. If restart is user-visible, treat it like a controlled shutdown.
Developers also sometimes use assembly metadata to locate the executable, which may not match the real deployed process path in all hosting setups. Environment.ProcessPath is usually a better fit on modern .NET.
Finally, single-instance protections can block the new process unless you coordinate the handoff carefully.
Summary
- Restarting WPF means launching a new process and then calling
Shutdown. - '
Environment.ProcessPathis the easiest way to locate the current executable.' - Preserve command-line arguments when startup behavior depends on them.
- Save settings before restart so changes survive the relaunch.
- Watch for single-instance locks that can block the replacement process.
Related reading
- How do I restart my C WinForm Application?
- How do I round a float upwards to the nearest int in C?
- How do I run a Python script from C?
- How do I run a Python script from C?
- How do I run Visual Studio as an administrator by default?
- How do I safely cast a System.Object to a bool in C?
- How do I save a stream to a file in C#?
- How do I save a stream to a file in C?

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.