Multiple Copy Problem

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

How do you get c# to only allow one copy of a program to be running?

ie. if a user trys to run a program that is already running the program will
just restore its original size rather than starting a new one


cheers in advance

Steve
 
Cathal Connolly said:
Try http://www.syncfusion.com/faq/winforms/search/550.asp . Please note if
your application is running in a partial trust enviroment, you may have some
issues with this code, so be sure to test.

That's not a good way of doing it, IMO:

1) It relies on the program only being in one place
2) It has a race condition (two processes could be launched at the same
time, both notice that the other one exists, and both quit)

A better solution is to use a Mutex. See
http://www.pobox.com/~skeet/csharp/faq/#one.application.instance
 
Back
Top