2

I am developing a WPF application using MVVM Light.

I would like to know how to check and prevent the user from running more than one instance of the application?

Thank you for your help.

Romain

Romain
  • 103
  • 2
  • 11

3 Answers3

2

Arik Poznanski write an article about this subject on his blog.

Here is the link to the first article

And here is the link to the update

Romain
  • 121
  • 2
1

You can check running processes on application startup and exit if copy is already present:

var appProcessName = Process.GetCurrentProcess().ProcessName;
var matchingProcesses = Process.GetProcessesByName(appProcessName);
if (matchingProcesses.Any())
{
    // Exit
}
k.m
  • 30,794
  • 10
  • 62
  • 86
0

I think what you are looking for is called a single instance mutex. Google has many results, but I used one recently from this thread for a Windows Forms app.

https://stackoverflow.com/a/7810107/1718702

Community
  • 1
  • 1
HodlDwon
  • 1,131
  • 1
  • 13
  • 30
  • Yes, I have looked for it on Google before but I did not find any results pertaining to MVVM light. Actually I want to know where to put the code to check for the instance. In App.xaml.cs? In MainViewModel.cs? – Romain Jan 13 '13 at 09:29
  • Ah, I don't have any experience with mvvm. Sorry :( – HodlDwon Jan 13 '13 at 09:35
  • Did you find out how to do it? The App StartUp event which is the right place to put a mutex for a single instance application on a common WPF scenario is not working. – Pantelis Dec 06 '13 at 08:11