本文介绍了无法删除MultiSourceFrameArrived的事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好。
我正在使用C#开发KINECT应用程序。
I'm developing KINECT application with C#.
我想在MultiSourceFrame到达时触发一个事件第一次。我编写了如下代码...
I want to fire an event when MultiSourceFrame is arrived just first time. I wrote code like followings...
private EventHandler<MultiSourceFrameArrivedEventArgs> handler = null;
public void Ready()
{
// setup multisoruceframe
kinectReader = KinectSensor.OpenMultiSourceFrameReader(frameTypes);
// setup event halder
handler = (sender, e) =>
{
// do something
// and remove handler
kinectReader.MultiSourceFrameArrived -= handler;
};
// add handler
kinectReader.MultiSourceFrameArrived += handler;
}
但处理程序未被删除。
MultiSourceFrameArrived的删除访问器是否正常工作?
Is MultiSourceFrameArrived's remove accessor working ?
问候。
推荐答案
尝试这一点,看看是否有帮助。
Try this and see if this helps.
而不是在委托中使用复制的对象KinectReader,而是将发送者转换为KinectReader对象,并从中移除多源帧到达的事件处理程序项。清单。
Instead of using the copied object KinectReader inside your delegate, convert sender to the KinectReader object instead and remove the multisource frame arrived event handler item from the list.
// setup event handler
handler = (sender, e) =>
{
var kinectReader = (MultiSourceFrameReader)sender;
// do something
// and remove handler
kinectReader.MultiSourceFrameArrived -= this.handler;
};
这篇关于无法删除MultiSourceFrameArrived的事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!