I need a event to detect Internet connect/disconnect

前端 未结 6 2054
清酒与你
清酒与你 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:23

    You can use the NetworkChange class, with the NetworkAvailabilityChanged event:

    NetworkChange.NetworkAvailabilityChanged += myNetworkAvailabilityChangeHandler;
    

    Since it's a system event, make sure you delete the event when you're finished, see this post here: You need to be careful about using event handler for NetworkChange

提交回复
热议问题