2
我正在嘗試ping代理,並且在繼續執行我的代碼之前,響應時間需要多長時間才能ping,但是我的秒錶太快了。我在哪裏錯了?C#如何等待代理ping?
private async void idunno()
{
Stopwatch stopWatch = new Stopwatch();
stopWatch.Start();
var x = await CanPing2();
Console.WriteLine("is proxy alvie: " + x);
stopWatch.Stop();
int ts = stopWatch.Elapsed.Milliseconds;
Console.WriteLine("RunTime " + ts);
Console.WriteLine("RunTime " + ts2);
}
public async Task<bool> CanPing2()
{
string ip = "170.130.59.107";
Console.WriteLine(ip);
Ping ping = new Ping();
try
{
PingReply reply = await ping.SendPingAsync(ip, 6000);
if (reply == null) return false;
Console.WriteLine("cp2 is alive: " + IPStatus.Success);
return (reply.Status == IPStatus.Success);
}
catch (PingException e)
{
Console.WriteLine("cp2: ex: " + IPStatus.Success);
return false;
}
}
你現在幾點鐘?你在等什麼? – arbitrarystringofletters
我得到2-600ms,我期待6000ish – user6793946