当前位置: 编程技术>.net/c#/asp.net
c#判断网络连接状态的示例分享
来源: 互联网 发布时间:2014-10-28
本文导语: 代码如下:public partial class Form1 : Form { [DllImport("wininet.dll")] private extern static bool getInterState(out int conn, int val); public Form1() {InitializeComponent(); getNet(); } //判断当前是否连接入Internet网络private void getNet(){int Out;if (getInterState(out Out...
代码如下:
public partial class Form1 : Form {
[DllImport("wininet.dll")]
private extern static bool getInterState(out int conn, int val);
public Form1() {
InitializeComponent();
getNet();
}
//判断当前是否连接入Internet网络
private void getNet()
{
int Out;
if (getInterState(out Out, 0) == true)
{
label1.Text = " 网络已连接!";
}else{
label1.Text = " 网络未成功连接!";
}
}
}