65.9K
CodeProject is changing. Read more.
Home

Video tip C#: Ensure only one instance is running

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Nov 2, 2011

CPOL
viewsIcon

5587

I really like this method, very easy to implement and understand. One minor "gotcha" about doing it this way is that it is still possible to run multiple instances under different user accounts simultaneously if the users are not administrators on the PC. If this is a scenario you need to avoid,...

I really like this method, very easy to implement and understand. One minor "gotcha" about doing it this way is that it is still possible to run multiple instances under different user accounts simultaneously if the users are not administrators on the PC. If this is a scenario you need to avoid, you can use a mutex. So, on startup, the application would:

  1. Check to see if the mutex exists already.
  2. If (1) close, else open and create the mutex.