How to return a value with Dispatcher.Invoke?

toni picture toni · Mar 22, 2010 · Viewed 24.2k times · Source

Anyone knows how to return a value from Dispatcher.Invoke in ? I want to return the selected index for a ComboBox.

Thanks!

Answer

user216652 picture user216652 · Jul 14, 2011

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.