How does GeoCoordinateWatcher.PositionChaged event work inside a periodic task?

我是研究僧i 提交于 2019-12-11 06:24:10

问题


How does GeoCoordinateWatcher.PositionChaged event work inside a periodic task? If I have a background agent that runs every one hour. Code is

 protected override void OnInvoke(ScheduledTask task)
 {
   GeoCoordinateWatcher watcher = new    
   GeoCoordinateWatcher(GeoPositionAccuracy.Default);
   watcher.MovementThreshold = 100;
   watcher.PositionChanged += _watcher_PositionChanged;
   watcher.Start();
  }

If initially the device was at postion A and device travelled more than 100m within the next hour, then after 1 hour when the onInvoke() is called will _watcher_PositionChanged get fired?


回答1:


No. The next time OnInvoke is called, you instantiate a new GeoCoordinateWatcher and it will only raise the PositionChanged event from that moment on. It has no clue where it has been earlier, it has just been born.

You will need to save your coordinate and refer to it on every OnInvoke call and manually call your PositionChanged code if needed.



来源:https://stackoverflow.com/questions/10871574/how-does-geocoordinatewatcher-positionchaged-event-work-inside-a-periodic-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!