暂停Kinect Camera - SDK调节事件处理程序可能出错

时间:2012-02-24 04:45:51

标签: c# wpf kinect

我正在将 Microsoft SDK Beta 代码转换为2012年2月发布的 Microsoft SDK官方发布

我添加了一个通用PauseKinect()来暂停Kinect。我的暂停只会删除更新图像的事件处理程序

优点:

  • 无重新初始化(30秒等待时间)

缺点:

  • Kinect仍在处理图片

暂停方法(仅限颜色)

internal void PauseColorImage(bool isPaused)
{
    if (isPaused)
    {
        _Kinect.ColorFrameReady -= ColorFrameReadyEventHandler;
        //_Kinect.ColorStream.Disable();
    }

    else
    {
        _Kinect.ColorFrameReady += ColorFrameReadyEventHandler;
        //_Kinect.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
    }
}

问题:

即使我正在删除该事件,为什么它仍然被触发?

注意:

当我暂停彩色图像时,我也会在其对象中暂停深度和骨骼。

侧面注意:

如果我取消注释我的代码它可以正常工作,但是重新初始化将会永远重新初始化我想要做的事情。

反射器中的MS

public void AddHandler(EventHandler<T> originalHandler)
{
    if (originalHandler != null)
    {
        this._actualHandlers.Add(new ContextHandlerPair<T, T>(originalHandler, SynchronizationContext.Current));
    }
}

public void RemoveHandler(EventHandler<T> originalHandler)
{
    SynchronizationContext current = SynchronizationContext.Current;
    ContextHandlerPair<T, T> item = null;
    foreach (ContextHandlerPair<T, T> pair2 in this._actualHandlers)
    {
        EventHandler<T> handler = pair2.Handler;
        SynchronizationContext context = pair2.Context;
        if ((current == context) && (handler == originalHandler))
        {
            item = pair2;
            break;
        }
    }
    if (item != null)
    {
        this._actualHandlers.Remove(item);
    }
}


public void Invoke(object sender, T e)
{
    if (this.HasHandlers)
    {
        ContextHandlerPair<T, T>[] array = new ContextHandlerPair<T, T>[this._actualHandlers.Count];
        this._actualHandlers.CopyTo(array);
        foreach (ContextHandlerPair<T, T> pair in array)
        {
            EventHandler<T> handler = pair.Handler;
            SynchronizationContext context = pair.Context;
            if (context == null)
            {
                handler(sender, e);
            }
            else if (this._method == ContextSynchronizationMethod<T>.Post)
            {
                context.Post(new SendOrPostCallback(this.SendOrPostDelegate), new ContextEventHandlerArgsWrapper<T, T>(handler, sender, e));
            }
            else if (this._method == ContextSynchronizationMethod<T>.Send)
            {
               context.Send(new SendOrPostCallback(this.SendOrPostDelegate), new ContextEventHandlerArgsWrapper<T, T>(handler, sender, e));
            }
        }
    }
}

1 个答案:

答案 0 :(得分:5)

在微软论坛上发布完全相同的问题并与多位微软代表交谈之后,他们基本上说“暂停”的唯一方法是启用/禁用流(取消注释我的评论)。没有直截了当地说它是SDK中的一个错误。他们将与开发团队中的人员交谈,并尝试在将来的版本中解决问题。

修改

在2012年5月的发布中,它仍然没有修复。谢谢微软!