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();
});
精彩评论