c# - The fastest way to check whether remote computer is offline -
i need fastest way check whether remote computer off. there ways i've tried, none of them gives me desired time speed (it should less 0.5 sec , it's critical, because occurs on context menu popup)
//using system.net iphostentry iphostinfo = dns.gethostentry(hostname); //if error occurs - remote computer off //using system.net.networkinformation ping ping = new ping(); pingreply pingreply = ping.send(hostip); if (pingreply.status != ipstatus.success) { //remote computer off } //using system.management managementscope scope = new managementscope(@"\\" + hostname + @"\root\cimv2", null); scope.connect(); //if error occurs - remote computer off
as far can see fastest way using dns.gethostentry(hostname) - still takes 3 sec throw exception. idea?
use ping timeout. version of send method allow specify how long wait response. if define 500ms , server checking not on other side of planet or on high latency internet connection, can quite reliably either target machine down or have problems internet connection.
dns.gethostentry not check whether host or down. works dns , tries resolve host name. dns can slow , can timeout if host name exists , used dns server not responsive.
Comments
Post a Comment