Creating (and restarting) a single-instance WPF application with SingleInstance.cs

Standard

My current project presented a unique challenge. I have a need to:

  1. allow only one instance of the application to run at each workstation,
  2. notify the user that an instance is already running if a second instance is started, and
  3. be able to programmatically restart the application.

Thankfully, Microsoft has provided the SingleInstance.cs to serve these needs. Following this article on CodeProject.com was a great start. The author Arik Poznanski did an excellent job explaining the steps necessary to implement the first two requirements. I combined his techniques with information found in this article on StackOverflow.com to fully satisfy all three requirements – an application that will only allow one instance, that will notify the user that an instance is already running, and that can easily be restarted programmatically. Continue reading