如何使用Dispatcher.Invoke返回值? [英] How to return a value with Dispatcher.Invoke?

查看:443
本文介绍了如何使用Dispatcher.Invoke返回值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都知道如何从 Dispatcher 调用 ?我想返回组合框的选定索引>。

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

谢谢!

推荐答案

还有另一种返回值的方法来自Invoke():

There's another way that returns value from Invoke():

object oIsLoaded = container.Dispatcher.Invoke( new Func<bool> ( () =>
    {
        return container.IsLoaded;
    })
);

顺便说一句,初始代码(与委托一起使用)很可能不会完全修改 oIsLoaded ;因此,我宁愿使用 Func<> 用于从此类函数返回值。

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.

这篇关于如何使用Dispatcher.Invoke返回值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆