使用C#判斷網絡是否通暢

 using System.Net.NetworkInformation;

    Ping pingSender = new Ping();
    PingReply reply = null;
    try
    {
        reply = pingSender.Send('www.yisaim.com', 1000);
    }
    catch (Exception)
    {
    }
    finally
    {               
        if (reply == null || (reply != null && reply.Status != IPStatus.Success))
        {
            MessageBox.Show("無法連接該網站,請檢查網絡!", "連接網站失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        else if (reply.Status == IPStatus.Success)
            //this.Text = "連接成功";
    }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章