3

If you place the following code in the game loop (Update or Draw) of a MonoGame app (can just be the default project template):

new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(150, 150);

It throws a cross-thread error...

The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

So then I tried this:

var dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, delegate
{
     new Windows.UI.Xaml.Media.Imaging.WriteableBitmap(150, 150);
});

Same error.

Looking under the covers, it doesn't look like MonoGame runs the game loop on a background thread or anything. It uses a synchronous loop.

Any ideas of a way to use WriteableBitmap in MonoGame? (I need to use it to render out some live tiles)

jonathanpeppers
  • 26,115
  • 21
  • 99
  • 182

1 Answers1

1

If you're using the Game class then your creating an application that by default does not support XAML.

Currently the best way to support XAML in a MonoGame app is to use the Siverlight-style XNA game as outlined in this thread...

http://monogame.codeplex.com/discussions/359544

Tom Spilman
  • 88
  • 2
  • 9
  • Got it working by making a Windows 8 specific subclass of my main `Game` object. Then used `GameTimer` inside it to call `Update` and `Draw` respectively. The Xaml side of the application just has to new up my `Game` class, and everything starts up. – jonathanpeppers Aug 30 '12 at 13:52