【问题标题】:"Pipe is being closed" when using the WinRT Geolocator使用 WinRT Geolocator 时“管道正在关闭”
【发布时间】:2012-06-29 06:34:07
【问题描述】:

当我使用 WinRT Geolocator 时,我偶尔会收到错误:

{"The pipe is being closed. (Exception from HRESULT: 0x800700E8)"}

同样,这是零星的。有什么建议吗?

Windows.Devices.Geolocation.Geoposition _Postion = null;
try
{
    var _Locator = new Windows.Devices.Geolocation.Geolocator();
    _Postion = await _Locator.GetGeopositionAsync();
}
catch { /* continue, null okay */ }

if (_Postion == null)
{ 
    /* use alternate */ 
}
else
{
    /* use location */ 
}

这是在模拟器中,但在本地机器上运行时也是如此。 通常这个错误不会导致中断。 它只是突然结束应用程序。 当它确实导致休息时。 这就是由此产生的错误。

【问题讨论】:

  • 除非您发布代码,否则我们无法为您提供帮助。当您发布代码时,我将取消我的反对票。
  • @Jerry Nixon 不错,您的代码示例帮助我理解了无用的 winrt 错误消息
  • @Jerry Nixon 你能帮我解决这个问题吗?当我在使用蜂窝网络的平板电脑上运行我的 Windows 商店应用程序时遇到此错误。

标签: c# geolocation windows-runtime


【解决方案1】:

我发现当您的本地化设置为“模拟”时会发生这种情况,如果您使用设备模拟器运行您的应用程序,您可以通过单击世界图标(在显示和相机设置之间)禁用此功能,然后取消选中“使用模拟位置”选项

【讨论】:

  • 我们在平板电脑中的何处获得此选项?
  • @KinjanBhavsar 你找到那个选项了吗?
  • @Musa 我在网上查了一下,发现这个:books.google.com/…希望对您有所帮助。
【解决方案2】:

我认为这个问题的根本原因是 GeoLocator 正在使用 Location API。

您得到的错误是 HRESULT_FROM_WIN32(ERROR_NO_DATA),它似乎映射到友好的(但在这种情况下是无用的)字符串“管道正在关闭”。当平台没有看到您的传感器提供有效报告时,这是预期的错误。

【讨论】:

    【解决方案3】:

    我的项目中也遇到过类似的零星异常。看我附上的图片截图。

    这是对我有用的解决方案,但我不确定它是否适用于其他人。

    这是我之前的代码:

    Geolocator loc = new Geolocator();
    try
    {
          loc.DesiredAccuracy = PositionAccuracy.High;
    
          Geoposition pos = await loc.GetGeopositionAsync();
          var lat = pos.Coordinate.Point.Position.Latitude;
          var lang = pos.Coordinate.Point.Position.Longitude;
          Status = loc.LocationStatus;
    
          return GetGpsInfoObject(pos);
    }
    catch (System.UnauthorizedAccessException)
    {
          return null;
    }
    

    我把代码改成:

    Geolocator loc = new Geolocator();
    try
    {
           loc.DesiredAccuracy = PositionAccuracy.High;
    
           Geoposition pos = await loc.GetGeopositionAsync();
           var lat = pos.Coordinate.Point.Position.Latitude;
           var lang = pos.Coordinate.Point.Position.Longitude;
           Status = loc.LocationStatus;
    
           return GetGpsInfoObject(pos);
    }
    catch (Exception)
    {
              return null;
    }
    

    【讨论】:

    • 所以只要发生异常就返回null
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 2022-10-13
    • 2011-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多