NetworkInformation NetworkStatusChanged event fired twice

蹲街弑〆低调 提交于 2019-12-06 11:30:52

I remember this being an issue. Seems like it still is.

http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/520ea5e2-cc17-486d-815e-528ca041d77f/

To solve your problem, keep track of the network availability with a flag and only update if the previous network status was unavailable.

In out testing we found that you will receive the even once per available adapter. We have 5 adapters so every time we plug a cable back in we seem to get an event as many times as there are active (enabled) adapters. We tested this by disabling one of the adapters and the number of the events reduced by exactly one and vice verse. It seems we only get one event for disconnect though.

The other reason for you event to be firing more than once is the fact that your network does actually drops and reconnects.

In any case its on you to write the code defensively to deal with the reality of the implementation and general unreliability associated with network connections.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!