C#測試網路連線測試
阿新 • • 發佈:2018-11-10
直接上程式碼,你們懂得
private void checkNetConnect() { string url = "www.baidu.com"; string state = ""; Ping ping = new Ping(); try { PingReply reply =ping.Send(url); if (reply.Status==IPStatus.Success) { this.pictureBox3.Image=Test.Properties.Resources.connected; state = "Netconnect Normal"; this.label1.Text = state; } if (reply.Status==IPStatus.TimedOut) { this.pictureBox3.Image = Test.Properties.Resources.noconnected; state = "Netconnect Abnormal"; this.label1.Text = state; } } catch (Exception ex) { string exceptions = ex.Message.ToString(); throw new ApplicationException(exceptions); } }