views:

91

answers:

4

Hi,

I have an installation program in which I would like to make sure my application is not currently running. If it is, I would like to close it (not kill it, since the app has to save some data on exit). The additional problem is that the window of my application is hidden (the tray icon is shown instead), so Process.MainWindowHandle is always 0.

What can I do to signal my application to close? Can I send a message directly to the Application (not the window)?

Your help will be greatly appreciated. Gregor

+1  A: 

You can probably have APP1 listen to a specific port and send a message to that port when you want the App to gracefully close. So APP2 has to be aware of APP1 ports and what message parameters it's expecting.

You can also have some sort of Message Queue (Windows has it or you might want to use something like SQL Service Broker) implementation and have one APP sending messages to the Queue and the other reading from the Queue

You might also check this out: http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx

Flavio
A: 

You can use PostThreadMessage WinAPI function (via PInvoke).

gandjustas
+2  A: 

Just to throw something else into the mix: named pipes.

snemarch
+1  A: 

You could probably use WINAPI to find the window handle (even if it is hidden) by class or window text. Then send a windows message to the application to close it.

http://support.microsoft.com/kb/178893

Mike Cheel