1

I have a loader.exe with Main() that loads the 'UI' in WPF, the thing is that I want only one instance of the loader.exe, how can I achieve it?

Is there a way a user clicks loader.exe it should check if an existing loader.exe is running and does nothing.

currently I have

loader.exe

with

main() 
....
..
Load UI
...

the loader has no idea what its loading etc so I can't do many things with the loader project...

Any help n code is highly appreciated

Thanks in advance.

abmv
  • 7,042
  • 17
  • 62
  • 100

3 Answers3

2

Have a look at:

http://yogesh.jagotagroup.com/blog/post/2008/07/03/Ways-of-making-a-WPF-application-Single-Instance.aspx

Also, you might find a more detailed answer in the following post here on StackOverflow:

What is the correct way to create a single-instance application?

Community
  • 1
  • 1
Winston Smith
  • 21,585
  • 10
  • 60
  • 75
2

We use the following C# code to detect if an application is already running:

using System.Threading;

string appSpecificGuid = "{007400FE-003D-00A5-AFFE-DA62E35CC1F5}";    
bool exclusive;
Mutex m = new Mutex(true, appSpecificGuid, out exclusive);
if (exclusive) {
    // run
} else {
    // already running
}

Regards, tamberg

tamberg
  • 1,987
  • 14
  • 23
  • This sorta worked in my case with my loaded code that did all the initialization untethered. Thanks – abmv Nov 23 '08 at 11:30
0

This is my simple and useful solution: http://blogs.microsoft.co.il/blogs/maxim/archive/2010/02/13/single-instance-application-manager.aspx

Maxim
  • 11
  • 1