Skip to content

Latest commit

 

History

History
32 lines (18 loc) · 1.18 KB

File metadata and controls

32 lines (18 loc) · 1.18 KB

WPF app Single Instance in one line of code

Usage

  • Add the following code to your App.xaml.cs or to a main window of your WPF app.

To have a single instance per user's Windows session:

WpfSingleInstance.Make("MyWpfApplication");

To have one instance per machine:

WpfSingleInstance.Make("MyWpfApplication", uniquePerUser: false);

Example

This repository contains a small WPF-application. You can build and run it to give it a try.

Differences from MS solution

  • No additional inheritance.
  • No App.xalm deletion.
  • No redundant WCF and Remoting undercover interactions.
  • It works with using of EventWaitHandle and it is so simple.

I heard that others evolved my approach significantly. Look out to those projects too.

P.S.: Consider passing of a string-name to EventWaitHandle.OpenExisting(...) as something vulnerable.

JFYI: This approach was created many years ago and updated for VS 2019. Now it's your turn to make improvements for it :)