开发者

use lambda expressions as parameter in Dispatcher.Invoke()

I have such problem : there is some method

private List<int> GetStatusList()
        {
            return (List<int>)GetValue(getSpecifiedDebtStatusesProperty);
        }

To invoke it in main thread - I use

`delegate List<int> ReturnStatusHandler();` ...

this.Dispatcher.Invoke(new ReturnStatusHandler(GetStatusList));

How can I do the same, using lambda expression instead of custom del开发者_C百科egate and method?


you can pass this:

new Action(GetStatusList)

or

(Action)(() => { GetStatusList; })


You can avoid explicit casting by creating a simple method:

void RunInUiThread(Action action)
{
     Dispatcher.Invoke(action);
}

Use this as follows:

RunInUiThread(() =>
{
     GetStatusList();
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜