Linux教程網
C#檢測當前用戶網絡是否連接代碼如下:
[csharp]
- [DllImport("wininet.dll")]
[csharp]
- private extern static bool InternetGetConnectedState(int Description, int ReservedValue);
- public static bool IsConnectedToInternet()
- {
- int Desc = 0;
- return InternetGetConnectedState(Desc, 0);
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- //檢測網絡狀態
- if (!IsConnectedToInternet())
- {
- MessageBox.Show("當前不能連接到服務器,請檢查網絡、防火牆等設備!");
- return;
- }
-
- }
Copyright ©
Linux教程網 All Rights Reserved