While working with the XNA Framework in Windows Phone 7 application, you might face an exception which says “Invalid Operation Exception” with a message “FrameworkDispatcher.Update has not been called”.
This exception generally occurs when you are working with the sound effects. In this post, we will discuss about this exception and the solution to fix it.
While working with the sound effects of XNA Framework in Windows Phone application, you might get an “Invalid Operation Exception” if you didn’t update the Framework Dispatcher properly. Here is the screenshot of the said exception:
The exception details clearly says that the FrameWorkDispatcher.Update() was not called. Here is the exception message for you:
FrameworkDispatcher.Update has not been called. Regular FrameworkDispatcher.Update calls are necessary for fire and forget sound effects and framework events to function correctly.
The FrameworkDispatcher.Update() method called by the framework automatically if the application implements the “Game” class. The Game.Update() method automatically processes the said method by triggering the event processing in the XNA framework.
If you don’t use the “Game” class in an application which uses the XNA Framework, you must have to call the method FrameworkDispatcher.Update() explicitly, otherwise you will get the above exception in your application.
Event based systems place messages in a message queue and keep it for dispatching. XNA framework messages also follows it and places them in a queue which will be processed by the XNA framework. If you come across such exception detailed above, you have to call the FrameworkDispatcher.Update() method once per frame in a timer loop. You can also implement the IApplicationService interface and use the timer Tick event.
Here is the sample implementation code for IApplicationService to update the FrameworkDispatcher:
public class DispatcherService : IApplicationService
private DispatcherTimer m_dispatcherTimer;
m_dispatcherTimer = new DispatcherTimer();
m_dispatcherTimer.Interval = TimeSpan.FromTicks(10000);
m_dispatcherTimer.Tick += frameworkDispatcherTimer_Tick;
void frameworkDispatcherTimer_Tick(object sender, EventArgs e)
void IApplicationService.StartService(ApplicationServiceContext context)
Now, you need to register this service in your application class (either XAML or Code behind). Here is the XAML code that you need to add in your App.xaml file:
I hope that this small tip will help you to fix the exception easily. You might have came to this page by searching the said exception message online. So, stay tuned to my blog for different articles on Technologies like Silverlight, Windows Phone, WPF, XAML, .NET and other stuffs.
Don’t forget to connect with me on Twitter and Facebook for technical updates and articles news. Also subscribe to my blog’s Newsletter to get all the updates delivered directly to your inbox. We won’t spam or share your email address as we respect your privacy.