UWP NetworkConnectionChanged事件
我正在开发一个UWP应用程序,在丢失网络连接或再次连接设备后需要做一些事情。
连接丢失或连接后是否有任何事件触发?
我搜索了www,但我发现的任何东西都是WP8 …
我需要在Windows 10上使用UWP。
我试图使用NetworkInformation.NetworkStatusChanged
。
我也有同样的问题。 这篇文章(以及整个网站)帮助了我很多: http : //windowsapptutorials.com/windows-10/how-to-check-for-network-availability-in-universal-windows-apps/
我希望这就是你需要的。 问题是,您只能检测是否连接了WiFi或移动网络。 如果您使用wifi连接并拔下路由器上的插头,则无法检测到它。
现在我这样做:
public static bool IsInternetConnected() { var isInternetConnected = false; var connectionProfile = NetworkInformation.GetInternetConnectionProfile(); if (connectionProfile != null) { var connectivityLevel = connectionProfile.GetNetworkConnectivityLevel(); isInternetConnected = connectivityLevel == NetworkConnectivityLevel.InternetAccess; } return isInternetConnected; }
我相信这种方法在模拟器中不起作用,但我不确定。 (目前正在重新安装VS15,因此我无法再次测试它)。
希望我能帮助你。
- ADAL .Net Core nuget包不支持UserPasswordCredential
- Azure Fluent API创建SQL Server时出错 – 缺少x-ms-request-id标头
- 如果MSB3277出现在asp net core app中该怎么办
- 如何从.net核心IoC容器中删除默认服务?
- 如何将WebClient与.NetCore一起使用?
- 在.NET Core中使用Reflection
- 如何从.net核心中的appsettings.json中提取列表
- 是否支持.NET Core中的Microsoft.AspNet.WebApi.Client?
- .net核心中的WCF(TransportWithMessageCredential)