Windows Phone 8 连接处理程序/互联网可用性 [英] Windows Phone 8 Connection Handler / Internet Availability

查看:29
本文介绍了Windows Phone 8 连接处理程序/互联网可用性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的团队正在研究团队项目应用程序.目前,我们需要一个事件处理程序来检查连接状态(如果它是开/关).

My team is working on a team project aplication. At the moment, we need an event handler to check the connection status (if it's on/off).

我对 System.Net.NetworkInformation 命名空间寄予厚望,但不幸的是,wp8 不支持大多数重要的东西.

I had big hopes in the System.Net.NetworkInformation Namespace, but unfortunately most important things aren't supported in wp8.

有人能帮我一下吗?

编辑 1#

看来,我没有很好地说明我的问题.我正在使用 Mvvm light expresion,它不支持该命名空间,或者至少我无法添加它.

It seems, I didn't specifed my problem well. I'm using Mvvm light expresion, and it does not support that namespace or at least I can't add it.

我是使用 VS 和 c# atm 的新手,可能我做错了什么,但只是当我尝试将引用添加到我的项目时,它没有列出.

I'm a newbie in using VS and c# atm, mayby I'm doing someting wrong, but simply when im trying to add the refernce to my project it does not list.

推荐答案

我还没有在 WP8 上尝试 System.Net.NetworkInformation 命名空间.但是新的 WP8 Windows.Networking.Connectivity Windows Phone 运行时命名空间工作得很好.

I haven't tried the System.Net.NetworkInformation namespace on WP8. But the new WP8 Windows.Networking.Connectivity Windows Phone Runtime namespace works just fine.

使用 Windows.Networking.Connectivity.NetworkInformation.NetworkStatusChanged 了解网络状况何时发生变化,并使用 Microsoft.Phone.Net.NetworkInformation.NetworkInterface 属性或 Windows.Networking.Connectivity.NetworkInformation 属性查看发生了什么.

Use Windows.Networking.Connectivity.NetworkInformation.NetworkStatusChanged to know when network conditions change and use Microsoft.Phone.Net.NetworkInformation.NetworkInterface properties or Windows.Networking.Connectivity.NetworkInformation properties to see what's up.

    private async void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        PrintNetworkStatus();

        NetworkInformation.NetworkStatusChanged += NetworkInformation_NetworkStatusChanged;
    }

    void NetworkInformation_NetworkStatusChanged(object sender)
    {
        PrintNetworkStatus();
    }

    private void PrintNetworkStatus()
    {
        Dispatcher.BeginInvoke(() =>
        MessageBox.Show(NetworkInterface.NetworkInterfaceType +
                        Environment.NewLine +
                        NetworkInterface.GetIsNetworkAvailable()));
    }

当我在 WP8 Lumia 920 上测试此代码片段时,它按预期工作.当我的手机仅连接到 WiFi 时,在启动时我看到以下消息框:

When I test this code snippet on my WP8 Lumia 920 it works as expected. On startup when my phone is on WiFi only I see the following MessageBox:

一旦我关闭了我的 WiFI 路由器并且手机上的 WiFi 连接丢失,我就会看到以下消息框:

And once I shutdown my WiFI router and the WiFi connection on the phone is lost I see the following MessageBox:

这篇关于Windows Phone 8 连接处理程序/互联网可用性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆