I have a program with a Geospace card built into it. Event processing for the card is processed in a separate thread so that the card responds (for example, events that fire when a card is clicked).
The problem I am facing is when the card fires the event, my program needs to update some things in it gui, and also call back to the card in order to handle the placement of images on the map.
I tried wrapping the entire event handler method in this.Dispatcher.Invoke, which returns me to the main UI thread. This works great for updating my GUI, but when I call back on the map, I am still in the UI thread, which may cause some problems on the map.
Basically, to do this, I will have to run dispatcher.invoke every time I want to change a control on my gui. Is there a way I can automatically do this without wrapping every call in dispatcher.invoke? I hope all this makes sense.
Here is a sample code for the event I'm talking about.
private void Map_OnMapClicked(object sender, MapClickedEventArgs e) { this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() => { // Do something to update my gui })); Map.DoSomethingInTheMap(); this.Dispatcher.Invoke(DispatcherPriority.Normal, (Action)(() => { // Do something to update my gui })); //etc etc etc }
c # wpf dispatcher
user113164
source share