I need a fastest way to check whether remote computer is off. There are some ways I've tried, but none of them gives me desired time speed (it should be less than 0.5 sec and it's critical, because occurs on context menu popup)
//using System.Net
IPHostEntry ipHostInfo = Dns.GetHostEntry(hostName);
//if error occurs - remote computer is off
//using System.Net.NetworkInformation
Ping ping = new Ping();
PingReply pingReply = ping.Send(hostIp);
if (pingReply.Status != IPStatus.Success)
{
//Remote computer is off
}
//using System.Management
ManagementScope scope = new ManagementScope(@"\\" + hostName + @"\root\cimv2", null);
scope.Connect();
//if error occurs - remote computer is off
As far as I can see the fastest way is by using Dns.GetHostEntry(hostName) - but still it takes it about 3 sec to throw an exception. Any idea?
Because you're depending on so many factors (Network loads, Packet losses etc`), and additionally, when a computer is not responding immediately when he gets the request doesn't necessarily says it's online, you can't assume the computer is offline. I don't think you can do it any faster than a ping request.