Ping application B from A ?

G

GTi

I have two .NET 2 applications.
Application A need to check if application B is alive.
How can I do this?
In Win32 I just use PostMessage to B and it posted a message back to A
(no hang)
But I don't want to use pInvoke. Any other way to send a bit between
two application?
 
G

GTi

Yes - but it may be a little heavy for this... (?)
As I know it - it use TCP/IP for communications - then what about
Windows Firewall?
 
G

Guest

I use named mutex's for this:

1. App B creates a named mutex when it starts, and closes it when it exits
1a. If this fails, a previous instance of App B must already be running...

2. App A attempts to open the named mutex. If the open works, App B is
running.

Hope this helps

Brian.
 
G

GTi

Brian said:
I use named mutex's for this:

1. App B creates a named mutex when it starts, and closes it when it exits
1a. If this fails, a previous instance of App B must already be running...

2. App A attempts to open the named mutex. If the open works, App B is
running.

Hope this helps

Brian.

Brian,
Looks like what I need!
Can you post a simple samples for this?
Does this work if application B hangs/crash ?
B is is important program and must be running all the time. If not a
message must be sendt to user/support. In this case A check and
displays a warning on screen.
 
V

Vadym Stetsyak

Hello, GTi!

G> Yes - but it may be a little heavy for this... (?)
G> As I know it - it use TCP/IP for communications - then what about
G> Windows Firewall?

If applications are on the same machine then loopback can be used, firewall usually guard external network directions.

You can introduce tcp connection between applications. Then applications will be able to "ping" each other. You can send arbitrary data. The idea here is the connection.

You can also think of named pipes.

You can utilize TcpListener/TcpClient classes to create connection between apps.

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 
G

Guest

Pretty much what Vadym Stetsyak said, although the need for the timer is only
if you want to periodically check to see if app B is still alive. Otherwise,
you can just attempt to open the existing mutex anywhere in your code where
you want to do the "ping".

Brian.
 
M

mwolf

this is kind of hacky, but I have an app which checks to see if another
app needs to be restarted.... due to saids app reliance on an instance
of ie... and ie's love for dieing.

i ended having to use
Process[] all = Process.GetProcesses();

loop over processes looking for mine, if its not there I

Process client = new Process();
client.StartInfo.FileName = this.applicationPath;
client.Start();

I also look for possible hangs, by checking said apps output, and
killing it if it appears it needs a restart.

all[x].Kill();
 
W

William Stacey [MVP]

Remoting 2.0 also has an IPC channel.

--
William Stacey [MVP]

| Yes - but it may be a little heavy for this... (?)
| As I know it - it use TCP/IP for communications - then what about
| Windows Firewall?
|
 
V

Vadym Stetsyak

Hello, mwolf!

m> i ended having to use
m> Process[] all = Process.GetProcesses();

m> loop over processes looking for mine, if its not there I

m> Process client = new Process();
m> client.StartInfo.FileName = this.applicationPath;
m> client.Start();

m> I also look for possible hangs, by checking said apps output, and
m> killing it if it appears it needs a restart.

Why is it hacky?
IMO getting process list introduces overhead. Waiting on sync obj is more effective.
However, if the app that you watch for is not yours (you do not have access to its source )
you can use WMI 'query' to look for neede process.
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top