Reputation: 77
When working with Bing maps control for Windows 8 store apps creating a new Location object on non-UI thread causes an exception.
WinRT information: The application called an interface that was marshalled for a different thread.
Usually this would mean that i'm improperly trying to update the UI from a background thread but this can't be the case since this can be reproduced by placing a button in an empty Windows 8 store app project:
<Button Content="Click me" Click="Button_Click"/>
And adding an event handler like so:
private void Button_Click(object sender, RoutedEventArgs e)
{
Task.Run(() =>
{
var loc = new Location(1, 1);
});
}
Is the Location struct's constructor really doing something on the UI thread or am I missing something here?
Upvotes: 0
Views: 340
Reputation: 1557
I didn't go into the code to see what is happening in the Bing Maps classes, but you cannot create ANY Bing Map "UI" object outside of the UI thread. I think the constructor only test whether or not it is called on the main thread, and throws the exception if it's not the case.
Meaning that you must instantiate your Location object on the UI thread, but also your Polylines, Pins, Layers, etc.
Any element that will be added to a map Control, must be created within the UI thread.
Upvotes: 3