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.
The behaviour I want is
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.
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)?
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).
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.
----Added----- For those two persons who have answered to my questions with existing answers.
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?