title: .NET: How to open a file with an existing instance?
body: <p>I have an MDI file viewer. That is, my program can open multiple files in a single instance. By the way, my application is not a single instance application, so the users can open as many instances as they want.</p>
  
  <p>The behaviour I want is</p>
  
  <pre><code>When the user double-clicks a file in Windows Explorer,
  if there is an existing instance of my application,
     then open the file with that instance
  else
     open the file with a new instance.
  </code></pre>
  
  <p>I think this behaviour is very common. Internet Explorer 9 works like. So, I believe that there must have been many people who have already implemented this before. Is there any well-established .NET (C# is preferred) sample code for this (not using Win32 API's, if possible)?</p>
  
  <p>I guess the algorithm could be something like the following, but I don't know if it is the best or the cleanest code to implement it (not using Win32 API's).</p>
  
  <pre><code>At the program's start up
      1)If there are arguments in Main(),
           check for existing instances.
      2)If an instance exists,
           send a message to the instance so that it can open the file.
           Then exit.
      3)else
           open the file.
  </code></pre>
  
  <p>----Added-----
  For those two persons who have answered to my questions with existing answers.</p>
  
  <p>MY APPLICATION IS NOT A SINGLETON APPLICATION! Please. It's just like Internet Explorer 9. I was looking at WCF P2P, since I have to broadcast a file open message to every running instance of my application, then choose one among them. But using WCF P2P seems to be a lot of works for this, because it seems to be opening and listening to TCP ports. What would be the best practice?</p>