Dispatch.Invoke(新动作......)与参数 [英] Dispatch.Invoke( new Action...) with a parameter
问题描述
previously我有
Dispatcher.Invoke(新动作(()=> colorManager.Update()));
从另一个线程更新显示为WPF。由于设计,我不得不改变计划,我必须通过ColorImageFrame参数为我ColorStreamManager.Update()方法。
随着这个的链接,我修改了调度员:
Dispatcher.Invoke(新动作< ColorStreamManager,ColorImageFrame>((P,V)=> p.Update(V)));
它编译罚款,但不会跑的。 VS2010说参数计数不匹配。在我的 ColorStreamManager.Update()
方法,我有
RaisePropertyChanged(()=>位图)
;
有人能指出我上哪儿去了?
ColorStreamManager.Update()
方法的签名如下:
公共无效更新(ColorImageFrame帧);
您不想要的操作,有参数,因为调度
是不会知道什么要传递给方法。相反,你可以做的就是关闭了变量:
ColorImageFrame 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屋!