c# - 暂停 Kinect 相机 - SDK 重新保护事件处理程序时可能出错

标签 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));
            }
        }
    }
}

最佳答案

在 Microsoft 论坛上发布相同的问题并与多位 Microsoft 代表交谈后,他们基本上说“暂停”的唯一方法是启用/禁用流(取消注释我的评论)。不用说直接它是 SDK 中的错误。他们将与开发团队的人员交谈,并尝试在未来的版本中解决该问题。

编辑

在 2012 年 5 月的版本中,它仍未修复。感谢微软!

关于c# - 暂停 Kinect 相机 - SDK 重新保护事件处理程序时可能出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9425541/

相关文章:

c# - Lodash 相当于 TypeScript 中的 C# LINQ GroupBy 和 Select

c# - 在这个简单的 WPF 应用程序中实现进度条

c# - 如何验证 PasswordBox WPF

opencv - Kinect 深度图像

c# - 用于模拟物理 Kinect 传感器的驱动程序或 dll

c# - 从多个托管服务器调用相同的 WCF 服务

c# - log4net: Assembly System.Xml.XmlElement not referenced 错误,虽然没有使用

wpf - 有没有一种简单的方法可以绑定(bind)到 WPF 中的父行?

unity-game-engine - 检查 ARM 是否举起 Zigfu 和 Unity3D

C# : set default payment method in stripe