Using Interop from Silverlight to XNA

Must Read

Subprime Mortgage Refinance and Subprime Home Equity Loans

If you have credit problems in your past and a low credit score, if you decide you want to...

The Black Friday Ads Are Back

Who doesn't know the importance of Black Friday? It is the biggest shopping day and every shopper waits for...

The Fundamentals Objectives, Target Markets, and Products and Services

Things have changed dramatically over the past several years in terms of Web site design and development methodology. Back...

Työllisyysnäkymien master technology

MBA in Technology Management refers to a program that students, teaches how technology and infrastructure to manage the information...

Home Equity Loan – An Alternative For Our Urgent Needs

Owing a house is of great help in our lives as it is not only an addition to our...

Using a Homeowner Line of Credit to Consolidate Debts

A homeowner line of credit is a special type of loan that allows you to borrow money over an...

The following are some of the features of Windows Phone 7 that you may want to use in a Silverlight application where interop with XNA is required:

  • Accessing input gestures on the device, such as drag, pinch, and hold gestures
  • Playing multi-channel audio
  • Advanced sound effects (such as using the XNA Dynamic- SoundEffectsInstance class, which lets you submit packets on the fly, vary the pitch, and apply 3-D effects to the sound)
  • Recording audio

For the last two features in the preceding list, you must create an XNA asynchronous dispatcher service and initialize it in the constructor or startup event in your App.xaml.cs file. This is required to raise the events in Silverlight when they are raised by the XNA objects.

Creating and Using an XNA Dispatcher Service

The XNA run-time event mechanism is different from the Silverlight event mechanism. Events raised by XNA objects are available within the XNA game loop, but they are not automatically available to the Silverlight event mechanism. To expose XNA events to Silverlight application code, you can take advantage of the Silverlight ability to use application extension services. These are services that add functionality to an application, and that can be reused by many applications. They circumvent the requirement to use inheritance. For more information, see “Application Extension Services” on MSDN (

The following code example shows an XNA asynchronous event dispatcher service that you can use in your Silverlight applications.

using System;
using System.Windows;
using Microsoft.Xna.Framework;
using System.Windows.Threading;
namespace YourAppNamespace
public class XNAAsyncDispatcher : IApplicationService
private DispatcherTimer frameworkDispatcherTimer;
public XNAAsyncDispatcher(TimeSpan dispatchInterval)
this.frameworkDispatcherTimer = new DispatcherTimer();
+= new EventHandler(frameworkDispatcherTimer_Tick);
this.frameworkDispatcherTimer.Interval = dispatch
void IApplicationService.StartService(ApplicationService
Context context)
{ this.frameworkDispatcherTimer.Start(); }
void IApplicationService.StopService()
{ this.frameworkDispatcherTimer.Stop(); }
void frameworkDispatcherTimer_Tick(object sender, EventArgs e)
{ FrameworkDispatcher.Update(); }

The DispatcherTimer class is a .NET Framework class that is included in Silverlight. It executes on the application thread and can raise events at preset intervals. In the preceding XNAAsyncDispatcher example, the Tick event executes the Update method of the FrameworkDispatcher class, which is part of the XNA Framework. The FrameworkDispatcher class is an alternative mechanism to drive the update loop if the base class is not an XNA game.

For more information, see “DispatcherTimer Class” (http://msdn. aspx) and “FrameworkDispatcher.Update” (
com/en-us/library/microsoft.xna.framework.frameworkdispatcher. update.aspx) on MSDN.

After you create an XNA dispatcher service class, you can instantiate it in the constructor of your application class in the App.xaml.cs file. The typical tick rate for capturing and exposing XNA events is 50 milliseconds.

public App()
// other constructor code here …



Please enter your comment!
Please enter your name here

Latest News

Digital Marketing for Beginners

Digital marketing for starter, Let to basic learning about connecting with your audience in the right place...

What are 7 things poor people do that the rich don’t?

1. poor people watch TV in which people read books how many hours you spend in front of the TV and when...

Top 18 best small business ideas for beginners starting

A small business can be frightening and requires plenty of careful planning there are many small business ideas which can be beneficial...

Summer that makes you happy

We saw were already here I've been thinking about some of the things. I used to do with my husband even though...

4 Point to helpful tips specifically for caregivers

What you need to take a vacation. I know it sounds impossible creative and try to make it work for you almost...

More Articles Like This