AnsweredAssumed Answered

DoEvents() in WPF?

Question asked by azlotinesri-ca-esridist Employee on Apr 3, 2018
Latest reply on Apr 6, 2018 by mnielsen-esristaff

I am using a locator to geocode addresses and then add the locations to the map as graphics (geocode, add graphic to the map, repeat). As the code runs in a loop, the map freezes and becomes responsive again after the last address has been geocoded and added to the map. If there are 30 addresses, the map is frozen for 8 seconds and then all the graphics get added at once. I would like the map to refresh after each location graphic has been added, and be responsive at all times.

 

As I understand, this happens because the code runs in the default UI thread. One option to solve this is to use the WPF version of the Windows Forms DoEvents() statement:

Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));

I have not been able to make this work, as I am not sure where this line of code should go. 

 

A cleaner way perhaps is to use a background thread (BackgroundWorker) to do the geocoding. With this approach, however, I am running into problems accessing objects in the UI thread.

 

I am using ArcGIS Runtime 100.1.

Thanks for any suggestions!

Alex

Outcomes