Dispatch.Invoke( new Action…) with a parameter

前端 未结 2 1577
旧巷少年郎
旧巷少年郎 2021-01-01 20:05

Previously I had

Dispatcher.Invoke(new Action(() => colorManager.Update()));

to update display to WPF from another thread. Due to design

2条回答
  •  庸人自扰
    2021-01-01 20:29

    You don't want the action to have parameters, because the Dispatcher isn't going to know what to pass to the method. Instead what you can do is close over the variable:

    ColorImageFrame someFrame = ...;
    Dispatcher.Invoke(new Action(() => colorManager.Update(someFrame)));
    

提交回复
热议问题