Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There appears to be three well-known ways of implementing single-instance applications in .NET programs: the process method, the Mutex method, and the Visual Basic method.</p> <p>Michael Covington discusses the first two in his hint, <a href="http://www.ai.uga.edu/~mc/SingleInstance.html" rel="nofollow noreferrer">Ensuring that only a single instance of a .NET application is running</a>.</p> <p>There's a <a href="http://www.codeproject.com/KB/cs/SingleInstanceAppMutex.aspx" rel="nofollow noreferrer">CodeProject article</a> that discusses the Mutex method in more detail, including getting the window handle of the existing application so that you can then (somehow) communicate with it.</p> <p>Another <a href="http://www.codeproject.com/KB/cs/CSSIApp.aspx" rel="nofollow noreferrer">CodeProject article</a> describes how to use classes in the Microsoft.VisualBasic namespace (which is accessible from C#) to implement a single-instance application.</p> <p>I'm not at all familiar with the third method. Of the first two, they both work but as is pointed out in the linked articles, the Mutex method seems more robust. I don't know why Mutex was selected as the named object to use. Any of the named synchronization objects (EventWaitHandle, Mutex, Semaphore, etc.) would work.</p> <p>Communicating with the existing application presents more of a problem. I'd suggest you look into using named pipes, if all you need to do is send a relatively small message to the running application. Check out <a href="http://msdn.microsoft.com/en-us/library/system.io.pipes.namedpipeclientstream.aspx" rel="nofollow noreferrer">System.IO.Pipes.NamedPipeClientStream</a> for more information.</p> <p>I should also note that if you're worried about security, you'll need to secure whatever communications method you use. Any application that has sufficient permissions will be able to send information to your running application through the named pipe.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload