Reputation: 16768
I want my program to be startable only once (it doesn't matter if it can be started on other user-accounts).
If its already started and the .exe is opened again it should bring the main-window of the first instance to the front.
What's the easiest way to achieve this?
Upvotes: 2
Views: 1565
Reputation: 5758
You want to look into using the Mutex object. Basically when your program runs check to see if a Mutex exists the "your unique name", if it does - close application (do this check before loading all resources), otherwise create a Mutex with the unique name and load up your application as planned.
Upvotes: 0
Reputation: 15579
This blog series might be helpful (see other options subsequent parts linked at bottom). I personally like the method described in Part 4 since in the Windows Forms world I've had good success using the WindowsFormsApplicationBase
class.
Upvotes: 2