Can someone tell me How to ensure that the console app doesn't open a new window if one is already open when I run the exe file multiple times ?
Asked
Active
Viewed 254 times
-4
-
1I think you want a [Singleton pattern](http://en.wikipedia.org/wiki/Singleton_pattern#C%5F.23) implemented in your app, or this http://stackoverflow.com/questions/1403600/how-to-avoid-multiple-instances-of-windows-form-in-c-sharp – Steve Mar 27 '14 at 15:27
-
I tried using Mutex but can we also do the same using Singleton pattern ? Mutex uses Threading , instead I would like to achieve the same using OOPs ,can someone suggest thoughts in that way – Shekar Mar 27 '14 at 15:39
1 Answers
0
You could try creating a named mutex and if there is already a mutex with that name, exit.

Max Ehrlich
- 2,479
- 1
- 32
- 44
-
-
I tried implementing singleton on the program class but couldn't understand where should I implement the singleton to stop opening multiple instances, because whenever I click on .exe, it creates a separate App domain and a separate instance and so a specific console window, so here the instance would be specific to app domain so can I really implement singleton in this case ? if so How can I do that Any ideas pls? – Shekar Mar 27 '14 at 16:05
-
@Shekar To my knowledge you can't because each process has its own memory space, your singleton needs to do some kind of IPC in order to know there is another process somewhere, this is where the mutex comes into play – Max Ehrlich Mar 27 '14 at 16:39