471,337 Members | 1,134 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Ping application B from A ?

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?

Jan 31 '06 #1
9 1507
Did you consider using .NET remoting?
"GTi" <tu****@gmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
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?

Jan 31 '06 #2
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?

Jan 31 '06 #3
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.

Jan 31 '06 #4
GTi

Brian C. Barnes wrote:
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.

Jan 31 '06 #5
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
Jan 31 '06 #6
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.

Jan 31 '06 #7
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();

Jan 31 '06 #8
Remoting 2.0 also has an IPC channel.

--
William Stacey [MVP]

"GTi" <tu****@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
| 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?
|
Jan 31 '06 #9
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
Feb 1 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by wana | last post: by
reply views Thread by Adam Wayne | last post: by
1 post views Thread by Krish | last post: by
8 posts views Thread by TKowalcz | last post: by
6 posts views Thread by Dave Marden | last post: by
reply views Thread by SyGC | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.