I have a WPF application where one of the properties in the View Model will be populated as a call to a service. I have been following Stephen Cleary's excellent tutorials so far. He discusses one way of doing this here
In my case the view model is instantiated once per application. The application calls the Initialise method (custom method) on the view model passing in some information on the basis of which the View model is supposed to reach out to the service to get the property instantiated.
The problem is that the application can call the Initialise method multiple times (user moving around randomly) passing in new set of information. When this happens I need to discard the earlier running tasks (if any) which were called the previous time the Initialise was called, call the service with fresh set of information and ensure that the property is only bound to the result of the latest invocation.
Can someone help come up with a pattern to achieve this? Basically call an async method multiple times but keep only the last result.
Initializemethod a couple of times but with a diff between the calls?