c# vs2010 winfrom控件检测网络环境
写下以作备用,代码附上。
public partial class UserControl1 : UserControl, IObjectSafety { //检测网络状态 [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(out int connectionDescription, int reservedValue); /// <summary> /// 检测网络状态 /// </summary> private bool isConnected() { int I = 0; bool state = InternetGetConnectedState(out I, 0); return state; } private void update_Load(object sender, EventArgs e) { if (isConnected()) { //network is connected. } else { //network is not connected. }
}
}
作者:造梦者2013
出处:http://www.cnblogs.com/lipanpan/
本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。