How do I allow only one instance of a WPF application to run?
Thanks.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With