Skip to content

it3xl/WPF-app-Single-Instance-in-one-line-of-code

Repository files navigation

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 :)

About

WPF app Single Instance in one line of code

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages