c#mvc项目发布在iis上,运行过程中因为超时,等网络原因报错怎么把这些错误抛出,
写个定时器,每10秒访问一次,如果网路异常就报错。
private bool IsInternetAvailable()
{
try
{
Dns.GetHostEntry("www.google.com"); //using System.Net;
return true;
}
catch (SocketException ex)
{
return false;
}
}
if (IsInternetAvailable())
{
MessageBox.Show("联网成功!");
}
else
{
MessageBox.Show("网络出现故障...,暂时无法联网!");
}