1

我正在尝试制作一个简单的应用程序来切换 Windows 移动设备上的 WiFi 无线电,并发现 OpenNETCF.WIndowsMo​​bile 命名空间提供了一些宝石,使这项任务变得超级简单:

    private void button2_Click(object sender, EventArgs e)
    {
         var wifiRadio = (from radio in Radios.GetRadios()
               where radio.RadioType == RadioType.WiFi
               select radio).FirstOrDefault();

        if (wifiRadio != null)
            switch (wifiRadio.RadioState)
            {
                case RadioState.Off:
                    wifiRadio.RadioState = RadioState.On;
                    button2.Text = "Is On";
                    break;
                case RadioState.On:
                    wifiRadio.RadioState = RadioState.Off;
                    button2.Text = "Is Off";
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }                            
    }

这在第一次点击时完美运行。在所有后续点击中,RadioState 仍然报告相同(即使已切换收音机)。

重新启动应用程序后,RadioState 将再次返回正确的状态。

有没有办法刷新状态以便正确报告?

4

1 回答 1

2

我发现有一种刷新方法。如果其他人需要知道这里是如何使用它:

        private void button2_Click(object sender, EventArgs e)
    {
        var radios = Radios.GetRadios();
        radios.Refresh();

        var wifiRadio = (from radio in radios
               where radio.RadioType == RadioType.WiFi
               select radio).FirstOrDefault();

        if (wifiRadio != null)
            switch (wifiRadio.RadioState)
            {
                case RadioState.Off:
                    wifiRadio.RadioState = RadioState.On;
                    button2.Text = "Is On";
                    break;
                case RadioState.On:
                    wifiRadio.RadioState = RadioState.Off;
                    button2.Text = "Is Off";
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }                            
    }
}
于 2012-12-07T02:29:12.540 回答