带参数的Dispatch.Invoke(new Action ...)

ike*_*kel 15 .net c# wpf multithreading

以前我有过

Dispatcher.Invoke(new Action(() => colorManager.Update()));
Run Code Online (Sandbox Code Playgroud)

从另一个线程更新显示到WPF.由于设计,我不得不改变程序,我必须将ColorImageFrame参数传递给我的ColorStreamManager.Update()方法.

链接之后,我将我的调度程序修改为:

Dispatcher.Invoke(new Action<ColorStreamManager, ColorImageFrame>((p,v) => p.Update(v)));
Run Code Online (Sandbox Code Playgroud)

它编译得很好但根本不会运行.VS2010说"参数计数不匹配".在我的ColorStreamManager.Update()方法中,我有 RaisePropertyChanged(() => Bitmap);

有人可以指出我哪里出错了吗?

ColorStreamManager.Update()方法的签名如下:

 public void Update(ColorImageFrame frame);
Run Code Online (Sandbox Code Playgroud)

Ser*_*rvy 21

您不希望操作具有参数,因为Dispatcher它不会知道要传递给方法的内容.相反,你可以做的是关闭变量:

ColorImageFrame someFrame = ...;
Dispatcher.Invoke(new Action(() => colorManager.Update(someFrame)));
Run Code Online (Sandbox Code Playgroud)