You are not on the UI thread as the Timer callback is on a background thread, use Device.BeginInvokeOnMainThread
when updating UI elements in that case:
So when updating your label
instance in the callback, do this:
Device.BeginInvokeOnMainThread(() => label.Text = "" +i;);
If I were to update the text and update another element, would I just place a , after label.Text = ""+1or would I have to have a whole other line replicated,
The parameter provided to BeginInvokeOnMainThread
is an Action
, so you can execute as much code as needed on the UI thread using just one "block":
Device.BeginInvokeOnMainThread(() =>
{
...;
...;
...;
});
Or:
void UIThreadAction()
{
...;
...;
...;
}
Device.BeginInvokeOnMainThread(UIThreadAction);