C#异步版本的PingUrl
示例
static void Main(string[] args)
{
string url = "www.stackoverflow.com";
var pingTask = PingUrlAsync(url);
Console.WriteLine($"Waiting for response from {url}");
Task.WaitAll(pingTask);
Console.WriteLine(pingTask.Result);
}
static async Task<string> PingUrlAsync(string url)
{
string response = string.Empty;
var ping = new System.Net.NetworkInformation.Ping();
var result = await ping.SendPingAsync(url);
await Task.Delay(5000); //模拟慢速互联网
if (result.Status == System.Net.NetworkInformation.IPStatus.Success)
{
response = $"{url} is online";
}
return response;
}
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短