TDD in WinRT

While experimenting with TDD I run into a pretty nasty exception:

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

However after some investigation I found a very good solution here.

public async Task Test1()
      await ExecuteOnUIThread(() =>
           WriteableBitmap bitmap = new WriteableBitmap(1, 1);

public IAsyncAction ExecuteOnUIThread(DispatchedHandler action)
     return CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, action);

Happy coding!

One thought on “TDD in WinRT

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.