Dispatch.Invoke(新动作......)与参数 [英] Dispatch.Invoke( new Action...) with a parameter

查看:1835
本文介绍了Dispatch.Invoke(新动作......)与参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

previously我有

  Dispatcher.Invoke(新动作(()=> colorManager.Update()));
 

从另一个线程更新显示为WPF。由于设计,我不得不改变计划,我必须通过ColorImageFrame参数为我ColorStreamManager.Update()方法。

随着这个的链接,我修改了调度员:

  Dispatcher.Invoke(新动作< ColorStreamManager,ColorImageFrame>((P,V)=> p.Update(V)));
 

它编译罚款,但不会跑的。 VS2010说参数计数不匹​​配。在我的 Col​​orStreamManager.Update()方法,我有 RaisePropertyChanged(()=>位图);

有人能指出我上哪儿去了?

Col​​orStreamManager.Update()方法的签名如下:

 公共无效更新(ColorImageFrame帧);
 

解决方案

您不想要的操作,有参数,因为调度是不会知道什么要传递给方法。相反,你可以做的就是关闭了变量:

  Col​​orImageFrame someFrame = ...;
Dispatcher.Invoke(新动作(()=> colorManager.Update(someFrame)));
 

Previously I had

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

to update display to WPF from another thread. Due to design, I had to alter the program, and I must pass ColorImageFrame parameter into my ColorStreamManager.Update() method.

Following this link, I modified my dispatcher to:

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

It compiles fine but would not run at all. VS2010 says "Parameter count mismatch." In my ColorStreamManager.Update() method I have RaisePropertyChanged(() => Bitmap);

Could someone point out where did I go wrong?

The signature of ColorStreamManager.Update() method is the following:

 public void Update(ColorImageFrame frame);

解决方案

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)));

这篇关于Dispatch.Invoke(新动作......)与参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆