Dispatch.Invoke( new Action…) with a parameter

前端 未结 2 1574
旧巷少年郎
旧巷少年郎 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:21

    If you call Invoke with an Action delegate, you need to pass the two Action parameters to the Invoke call:

    ColorStreamManager colorManager = ...
    ColorImageFrame frame = ...
    
    Dispatcher.Invoke(
        new Action((p,v) => p.Update(v)),
        colorManager,
        frame);
    

    The Invoke overload you're using here is Dispatcher.Invoke(Delegate, Object[]).

提交回复
热议问题