【问题标题】:WP7 Popup delays opening when used with locations与位置一起使用时 WP7 弹出窗口延迟打开
【发布时间】:2011-03-02 19:45:03
【问题描述】:

我有以下代码:

ShowPoup(); 
if (_watcher == null)
{
    _watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
    _watcher.MovementThreshold = 15; // use MovementThreshold to ignore noise in the signal
    _watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
}

if (!_watcher.TryStart(true, TimeSpan.FromSeconds(3)))
{
    MessageBox.Show("Please turn on location services on device under Settings.");
    //HidePopup();
}

我的问题是直到 _watcher.TryStart() 方法返回后才会出现弹出窗口。弹出窗口的重点是显示加载叠加层,以告诉用户应用程序正在执行某些操作。在工作完成后显示它是没有意义的,此时我隐藏了弹出窗口,所以用户永远看不到任何东西。

我在整个应用程序中都有这个弹出代码,这是我第一次遇到这个问题。即使我在调用当前方法之前在单独的方法中调用 ShowPopup(),它仍然不会显示,直到 _watcher 启动之后。我不确定为什么会这样。

【问题讨论】:

    标签: c# windows-phone-7 popup geolocation


    【解决方案1】:

    您似乎在 TryStart 期间阻塞了 UI 线程。如果您可以将观察者初始化移动到后台线程(例如线程池),那么您可以保持显示“活动”。

    类似:

    ShowPoup(); 
    if (_watcher == null)
    {
        _watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
        _watcher.MovementThreshold = 15; // use MovementThreshold to ignore noise in the signal
        _watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
    }
    
    System.Threading.ThreadPool.QueueUserWorkItem((ignored) =>
    {
        if (!_watcher.TryStart(true, TimeSpan.FromSeconds(3)))
        {
            Dispatcher.BeginInvoke(() =>
            {
                HidePopup();
                MessageBox.Show("Please turn on location services on device under Settings.");
            }
        });
    });
    

    【讨论】:

    • 实际上,当 trystart 成功时,该代码需要另一个 HidePopup() - 但我希望你明白!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-12
    • 2014-02-10
    • 1970-01-01
    相关资源
    最近更新 更多