我正在将Microsoft SDK Beta代码转换为2012年2月发布的Microsoft SDK官方发行版.
我添加了一个通用PauseKinect()来暂停Kinect.我的暂停只会删除更新图像的事件处理程序
internal void PauseColorImage(bool isPaused)
{
if (isPaused)
{
_Kinect.ColorFrameReady -= ColorFrameReadyEventHandler;
//_Kinect.ColorStream.Disable();
}
else
{
_Kinect.ColorFrameReady += ColorFrameReadyEventHandler;
//_Kinect.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
}
}
Run Code Online (Sandbox Code Playgroud)
即使我正在删除事件,为什么它仍然被触发?
此外,当我暂停彩色图像时,我也会在其对象中暂停深度和骨骼.
如果我取消注释我的代码它可以正常工作,但是它将永远重新初始化,这不是我想要做的.
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));
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在微软论坛上发布一个相同的问题并与多个微软代表交谈之后,他们基本上说了"暂停"的唯一方法是启用/禁用流(取消注释我的评论).没有直截了当地说它是SDK中的一个错误.他们将与开发团队中的人员交谈,并尝试在将来的版本中解决问题.
在2012年5月的发布中,它仍然没有修复.谢谢微软!
| 归档时间: |
|
| 查看次数: |
648 次 |
| 最近记录: |