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?
No.
The next time
OnInvokeis called, you instantiate a newGeoCoordinateWatcherand it will only raise thePositionChangedevent 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.