[UWP] [C#]删除地理围栏时出错 [英] [UWP][C#]Get error when remove geofence

查看:103
本文介绍了[UWP] [C#]删除地理围栏时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

尝试删除地理围栏时出错

I get error when try to remove geofence

错误消息:操作尝试访问外部数据有效范围

Error Message: The operation attempted to access data outside the valid range

var geofences = GeofenceMonitor.Current.Geofences;
foreach (var item in geofences)
{
     if (item.Id.ToString() == fenceID.Text.ToString())
     {
          geofences.Remove(item);  
          GeofenceMonitor.Current.GeofenceStateChanged -= Current_GeofenceStateChanged;
           GeofenceMonitor.Current.StatusChanged -= Current_StatusChanged;
      }
}




谢谢!


THANK YOU!

推荐答案

从列表中删除项目时,不应使用foreach循环。  使用for循环,从最后一项开始,以第一项结束。  我怀疑foreach循环搞砸了,因为当您在列表中删除
时,项目位置会发生变化。
When removing items from a list you should not use a foreach loop.  Use a for loop and start with the last item and end with the first.  I suspect the foreach loop is getting messed up because the item positions are changing when you remove something in the list.


这篇关于[UWP] [C#]删除地理围栏时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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