Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF Enforce only ONE instance of application

How do I allow only one instance of a WPF application to run?

Thanks.

like image 829
John Batdorf Avatar asked Jan 05 '09 21:01

John Batdorf


People also ask

How do I make sure that only one instance of my application runs at a time?

The best way of accomplishing this is using a named mutex. Create the mutex using code such as: bool firstInstance; Mutex mutex = new Mutex(false, "Local\\" + someUniqueName, out firstInstance); // If firstInstance is now true, we're the first instance of the application; // otherwise another instance is running.

How do I allow only one instance of a program in C#?

Making a singleton application, i.e., preventing users from opening multiple instances of your app, can be easily implemented using a Mutex. A Mutex is similar to a C# lock, except it can work across multiple processes, i.e. it is a computer-wide lock.

What is single instance application?

A Single Instance application is an application that limits the program to run only one instance at a time. This means that you cannot open the same program twice.

What is Baml in WPF?

BAML file from assembly resources, parses it, and creates a corresponding WPF visual tree or workflow. Having this format, the content is loadable faster during runtime, because the XAML is enriched by tokens, and lexical analysis is completed.


1 Answers

http://blogs.microsoft.co.il/blogs/arik/archive/2010/05/28/wpf-single-instance-application.aspx

Doesn't require VB.DLL as some other examples advise. Has WPF sample code. Passes any cmd line args to initial instance.

like image 164
sobelito Avatar answered Sep 30 '22 14:09

sobelito