问题描述
GeoCoordinateWatcher.PositionChaged 事件如何在周期性任务中工作?如果我有一个每小时运行一次的后台代理.代码是
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();
}
如果最初设备在位置 A 并且设备在接下来的一个小时内移动了超过 100m,那么在 1 小时后调用 onInvoke() 时 _watcher_PositionChanged 会被触发吗?
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?
推荐答案
没有.下一次 OnInvoke
被调用时,你实例化一个新的 GeoCoordinateWatcher
并且它只会从那一刻起引发 PositionChanged
事件.它不知道之前在哪里,它刚刚出生.
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.
您需要保存坐标并在每次 OnInvoke 调用时引用它,并在需要时手动调用 PositionChanged 代码.
You will need to save your coordinate and refer to it on every OnInvoke call and manually call your PositionChanged code if needed.
这篇关于GeoCoordinateWatcher.PositionChaged 事件如何在周期性任务中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!