giammin

Check if another instance of the application is running

May 21st, 2013
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.56 KB | None | 0 0
  1. //simple,fast but not 100% reliable way to check if there are more instances of the current application
  2. public static bool IsUniqueInstance()
  3. {
  4.     string processName = Process.GetCurrentProcess().ProcessName;
  5.     var currentProcess = Process.GetProcessesByName(processName);
  6.     return currentProcess.Length == 1;
  7. }
  8.  
  9.  
  10. //this are more complex and reliable:
  11. //MUTEX version: http://odetocode.com/blogs/scott/archive/2004/08/20/the-misunderstood-mutex.aspx
  12. //MUTEX version with switch to application:  http://sanity-free.org/143/csharp_dotnet_single_instance_application.html
Advertisement
Add Comment
Please, Sign In to add comment