Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Cannot set some properties of a Label within a different thread (Task.Run) in Xamarin PCL

$
0
0

Maybe this doesn't have anything to do with Xamarin, just tesing my understanding of tasks in general I think. I have a task that creates a label among other things and it is in a task so I can keep the activityindicator spinning while it is running. Setting certain properties cause it to fail, for example (PCL) project:

private void Wtf()
{
Task.Run(() =>
{
var oLbl = new Label() { Text = "Order" }; // This works
var oLbl2 = new Label() { FontSize = 10, Text = "Order" }; // This fails
});
}

The error is "The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))" which seems pretty straight forward, but I don't understand how FontSize could be a different thread than the Text property;
Both 'Text' and 'FontSize' are properties of Label. Must be different somehow...?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>