判断网络是否连接
来源:互联网 发布:淘宝开店怎么收费标准 编辑:程序博客网 时间:2024/04/23 14:59
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Net.NetworkInformation;namespace IsNetWorking{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Ping p = new Ping(); PingReply pr; while (true) { try { pr = p.Send("www.baidu.com"); if (pr.Status != IPStatus.Success) { MessageBox.Show("No link!"); } else { MessageBox.Show("Is working!"); return; } } catch { } } } }}