【发布时间】:2014-12-07 16:20:15
【问题描述】:
在我的 Windows Phone 8 应用程序中,我尝试在主页上使用 GetGeopositionAsync 来根据用户位置显示一些项目。
调用 GetGeopositionAsync 不会在指定的超时时间内返回,它根本不会返回。
我使用的代码很简单:
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracyInMeters = 50;
Geoposition geoposition = null;
try
{
geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromMinutes(5),
timeout: TimeSpan.FromSeconds(10));
}
catch (UnauthorizedAccessException ex)
{
// location services disabled or other error
// user should setup his location
}
我能够找到的解决方案是为 GeoCoordinateWatcher 创建一个异步包装器,它似乎工作正常。 但我对我的解决方案不太有信心,我更喜欢使用 GetGeopositionAsync,这看起来像是在 WP8 中获取设备位置的推荐方式。
更新:其他人报告相同的行为: http://social.msdn.microsoft.com/forums/en-us/wpdevelop/thread/ff166fac-b423-4428-abd8-610bf0102fc0
【问题讨论】:
-
名为“IsBusy”的变量始终是创建死锁的好方法。我们看不到你还在哪里使用它。
-
请忽略。我在 await 之后和 catch 子句中放置了断点,但都没有到达
-
你调用
Wait还是Result进一步提高你的调用堆栈?
标签: windows-phone-8