Search code examples
c#wcf

How to ping from a Windows Service


I have a windows service that will connect to a WCF web service is due course. However, I like to see if the client has COMs (internet) available before attempt of a connection is made to my own web service. Pinging from the window service seems a good way of doing this. (its fast)

Are there any tutorials or example code out there I could see so I can do this?

Thanks


Solution

  • This should do it

    using(System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping())
    {
        {
        try
        {
            System.Net.NetworkInformation.PingReply reply = p.Send("127.0.0.1", 3000);
            if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
                return true;
        }
        catch(Exception ex) 
        {
    
        }
    }