什么是使用.NET来检查Internet连接的最佳方法是什么? [英] What is the best way to check for Internet connectivity using .NET?
本文介绍了什么是使用.NET来检查Internet连接的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是为您在.NET中的Internet连接?
What is the fastest and most efficient way to check for Internet connectivity in .NET?
推荐答案
这样的事情应该工作。
<一个href="http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx">System.Net.WebClient
public static bool CheckForInternetConnection()
{
try
{
using (var client = new WebClient())
{
using (var stream = client.OpenRead("http://www.google.com"))
{
return true;
}
}
}
catch
{
return false;
}
}
这篇关于什么是使用.NET来检查Internet连接的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文