问题
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