views:

81

answers:

1

Hi,

I found there are lots of posts showing how to detect if the application instance already running. But I cant find any one that shows how to access or use the same running application.

I have created shell menu items and linked them an application. For ex. If you right click on any folder it shows "OS Monitor". If i clicked on that an application is started. If I again right clicked on the folder and selected "OS Monitor" another instance of same application is started. I have to prevent this. Further more when user closes the "OS Monitor" form I just made it hidden. So that if the user again selects the same menu option then the same running form need to show.

I have created the application using C#2005. Does anybody have the idea how I could access the same running instance of the application.

Thanks in advance.

A: 

As address spaces of applications are separated, you have to use some global mechanism/object. An example is named mutexes: you create a named mutex, if it already exists, then the application was already running. Using Mutexes for ensuring that only one instance is running is presented on this blog

The second step is to communicate with the running instance. Therefore you have to use some IPC mechanism. Easiest is to use Windows messages if you are running Windows (like in the example from Blog). Note that this would not be portable to MONO as you have to make native calls. If that matters you could use a network connection among other possibilities. See answers to this question: IPC Mechanisms in C# - Usage and Best Practices.

After having transmitted the parameters to the running instance, you have to exit of course, otherwise you'll end up with two applications running. For a short time (the time of parameter transfer) you have indeed two instances running but only one effectively is doing the job.

This response was made under the assumption that you can/wish to make modifications to "OS Monitor".

jdehaan
Thanks jdehaan!!!You have provided a valuable information. I will try to implement this.
IrfanRaza