开发者

use lambda expressions as parameter in Dispatcher.Invoke()

开发者 https://www.devze.com 2023-04-12 02:35 出处:网络
I have such problem : there is some method private List<int> GetStatusList() { return (List<int>)GetValue(getSpecifiedDebtStatusesProperty);

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

精彩评论

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

关注公众号