C#: how to set DNS resolve timeout?
<p>I want to check if a host can be resolved，but I don't want to wait a long time; so I want to set a timeout.</p>
<p>I have tried</p>
<pre><code> public static bool ResolveTest(string hostNameOrAddress, TimeSpan time_out)
 {
     var result = Dns.BeginGetHostEntry(hostNameOrAddress, null, null);
     var success = result.AsyncWaitHandle.WaitOne(time_out);
     if (!success) {
         //throw new Exception(&quot;Failed to resolve the domain.&quot;);
         return false;
     }
     return true;
 }
</code></pre>
<p>but this is not working correctly, because when it's a wrong host, it also can return true. So how to set a timeout for DnsResolve?</p>