WP7 : FrameworkDispatcher.Update has not been called when recording audio(wp7 录音)

WP7录音时遇到".Update has not been called. Regular FrameworkDispatcher.Update calls are necessary for fire and forget sound effects and framework events to function correctly. ",找了资料是这么说的:

如果您一个应用程序使用XNA框架不执行游戏,例如一个Windows Phone应用程序中使用Silverlight应用程序模型,你必须XNA框架消息队列中调用自己FrameworkDispatcher.Update方法发送消息可以做到这一点,在一个定时器每帧循环一次或者可以实现一个DispatcherTimer Tick事件处理程序IApplicationService接口

方法1:调用xna类前加

  DispatcherTimer timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(33);
            timer.Tick += delegate { try { FrameworkDispatcher.Update(); } catch { } };
            timer.Start();

 2:

public class XnaAsyncDispatcher : IApplicationService
{
private readonly DispatcherTimer _frameworkDispatcherTimer;
public XnaAsyncDispatcher(TimeSpan dispatchInterval)
{
FrameworkDispatcher.Update();
_frameworkDispatcherTimer = new DispatcherTimer();
_frameworkDispatcherTimer.Tick += FrameworkDispatcherTimer_Tick;
_frameworkDispatcherTimer.Interval = dispatchInterval;
}
void IApplicationService.StartService(ApplicationServiceContext context)
{
_frameworkDispatcherTimer.Start();
}

void IApplicationService.StopService()
{
_frameworkDispatcherTimer.Stop();
}

private static void FrameworkDispatcherTimer_Tick(object sender, EventArgs e)
{
FrameworkDispatcher.Update();
}
}

参考:http://www.cjcraft.com/blog/2011/01/31/WP7DevTip017WhatToDoIfYouGetFrameworkDispatcherUpdateHasNotBeenCalledExceptionWhenRecordingAudioInWP7.aspx

原文地址:https://www.cnblogs.com/shit/p/2405902.html