An event running every few seconds, want it to run only once
I'm making a WPF application and for that using GeoCoordinateWatcher but the GeoCoordinateWatcher event is supposed to run only once until I want it to run again, but it automatically runs every seconds and i have no idea why.
The event name is SettingWeatherData
Keep in mind im a beginner and dont have a lot of idea bout events & delegates
https://pastebin.com/81UBJjPC
4 Replies
SettingWeatherData is not your event, that's your event handler. The event you subscribe to is the PositionChanged event which I imagine is triggered everytime the position changes
Make a boolean property and add a check for that property before executing the rest of the function.
I would look into the other options that the API provides and see if there's a better way to achieve what you want. For example, there is a position property that you can call whenever you want instead of relying on the event. There is also a MovementThreshold property that can be used to limit how often the position changes event fires (places a dependency on the distance moved)
ik im too late to respond but i fixed it soon after by unsubscribing from the event handler, ty for trying to help tho