I need a event to detect Internet connect/disconnect

前端 未结 6 2057
清酒与你
清酒与你 2020-11-27 13:44

We are developing a .NET application where one of the requirements is to monitor whether the system is connected to the internet or not.

We were able to get a .NET

6条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 14:38

    try with this:

    private void AvailabilityChanged(object sender, NetworkAvailabilityEventArgs e)
            {
                if (e.IsAvailable)
                    Console.WriteLine("Wi-Fi conectado " + DateTime.Now );
                else
                    Console.WriteLine("Wi-Fi desconectado " + DateTime.Now);
            }
    
    
            public Inicio()
            {
                InitializeComponent();
    
                NetworkAvailabilityChangedEventHandler myHandler = new NetworkAvailabilityChangedEventHandler(AvailabilityChanged);
                NetworkChange.NetworkAvailabilityChanged += myHandler;
            }
    

提交回复
热议问题