Ping application B from A ?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GTi

    Ping application B from A ?

    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?

  • Zvonko Keber

    #2
    Re: Ping application B from A ?

    Did you consider using .NET remoting?


    "GTi" <tunlid@gmail.c om> wrote in message
    news:1138712965 .966517.272390@ g44g2000cwa.goo glegroups.com.. .[color=blue]
    >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?
    >[/color]


    Comment

    • GTi

      #3
      Re: Ping application B from A ?

      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?

      Comment

      • Brian C. Barnes

        #4
        RE: Ping application B from A ?

        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.

        Comment

        • GTi

          #5
          Re: Ping application B from A ?


          Brian C. Barnes wrote:[color=blue]
          > 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.[/color]

          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.

          Comment

          • Vadym Stetsyak

            #6
            Re: Ping application B from A ?

            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

            Comment

            • Brian C. Barnes

              #7
              Re: Ping application B from A ?

              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.

              Comment

              • mwolf

                #8
                Re: Ping application B from A ?

                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.GetProc esses();

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

                Process client = new Process();
                client.StartInf o.FileName = this.applicatio nPath;
                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();

                Comment

                • William Stacey [MVP]

                  #9
                  Re: Ping application B from A ?

                  Remoting 2.0 also has an IPC channel.

                  --
                  William Stacey [MVP]

                  "GTi" <tunlid@gmail.c om> wrote in message
                  news:1138718125 .251649.285430@ g47g2000cwa.goo glegroups.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?
                  |


                  Comment

                  • Vadym Stetsyak

                    #10
                    Re: Ping application B from A ?

                    Hello, mwolf!

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

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

                    m> Process client = new Process();
                    m> client.StartInf o.FileName = this.applicatio nPath;
                    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

                    Comment

                    Working...