Anyone knows how to return a value from Dispatcher
.Invoke
in wpf? I want to return the selected index for a ComboBox.
Thanks!
Invoke(Action, DispatcherPriority, CancellationToken)Executes the specified Action synchronously at the specified priority on the thread the Dispatcher is associated with.
Describes the priorities at which operations can be invoked by way of the Dispatcher.
A dispatcher is often used to invoke calls on another thread. An example would be if you have a background thread working, and you need to update the UI thread, you would need a dispatcher to do it.
There's another way that returns value from Invoke():
object oIsLoaded = container.Dispatcher.Invoke( new Func<bool> ( () => { return container.IsLoaded; }) );
And by the way, chances are that the initial code (which is working with delegate) won't modify oIsLoaded
at all; So I'd rather use a Func<>
for returning a value from that kind of function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With