本文介绍了互联网连接检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,
我想开发一个可以在按下按钮的同时检查PC中可用互联网连接的应用程序.

请尽快帮助我.


问候,
Shawon Mahmud博士

Dear all,
I want to develop an application that check internet connection available in PC while pressing a button.

Please help me soon.


Regards,
Md. Shawon Mahmud

推荐答案

try
 {
    System.Net.IPHostEntry iPHostEntry = System.Net.Dns.GetHostEntry("www.codeproject.com");
 }
 catch
 {
    Console.WriteLine("No connection...");
 }



推荐方式:

http://msdn.microsoft.com/en-us/library/aa384702% 28VS.85%29.aspx [ ^ ]



Recommended way:

http://msdn.microsoft.com/en-us/library/aa384702%28VS.85%29.aspx[^]


using System.Net.NetworkInformation;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {

        }
        private void button1_Click(object sender, EventArgs e)
        {
            NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler(NetworkChange_NetworkAvailabilityChanged);
        }
        public void NetworkChange_NetworkAvailabilityChanged(Object sender, NetworkAvailabilityEventArgs e)
        {
            if (e.IsAvailable)
                MessageBox.Show("Connected");
            else
                MessageBox.Show("Disconnected");
        }
    }
}



这篇关于互联网连接检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 22:00