Click to See Complete Forum and Search --> : How to open files always in the same instace?


memeloo
May 22nd, 2009, 02:16 AM
can you give some clues how can I open files always in the same instace of my app? I have my custom file extension and I'd like to be able to load a file into a running instance of my program when I double-click it

Arjay
May 22nd, 2009, 02:02 PM
There is really two parts to this problem:
1) Detecting if your application is currently running.
2) Passing the file to the currently executing application.

For 1), you can add some code that checks for a previous instance of your application using a mutex. Just create a named mutex when you start the app and check if the mutex already exists. If it already exists, you will pass the file path to the original instance by calling IStartup.OpenFile(...) method (see 2) below) and then exit the app.

For 2), you'll need to develop some interprocess communication method to pass the file path to the existing instance of the application. There are many ways to do this, but consider hosting a WCF service in the app. Since WCF can be hosted in IE, a Windows service or an application, it's pretty simple to set up a simple service that exposes an interface and a method (say IStartup w/method OpenFile).

memeloo
May 25th, 2009, 02:43 AM
cool thx, that's exacly what I wanted to know, now I have something to go on ;)