This snippet shows how to use Mutex to prevent multiple copies of your software from running. For a WinForms application, this code goes into the Program.cs file.
The magic starts in line 14 where we attempt to create a Mutex. A Mutex is a form of a lock, but it has the ability to cross applications, not just locking within an application. We take advantage of this by creating one with a special name for our application (in this case "mydomain.com myprogramname"). You need to make sure this is unique to your software, so be as specific as you can. The 'false' portion tells the system that we don't claim ownership of the Mutex.
Next we call WaitOne on the Mutex with two parameters. The first is the number of milliseconds we are willing to wait to claim the 'lock' on this Mutex. In this case we set it to 3 seconds in case another application is in the process of shutting down so we give it some time to do so. The second parameter tells the system if we want continue before we know if we have the Mutex or not. If this method returns true, then we have the Mutex and can proceed with our application. Otherwise we pop up a MessageBox letting the user know that another copy is already running.
All of this is wrapped in a using {} clause. The reason for this is we want to make sure that we release the Mutex when the application ends, otherwise you won't be able to run it again until you reboot your machine! The using ensures that the Dispose method is called on our Mutex so that it releases the value.