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

await Task.Delay() doesn't seem to work in a Page constructor

$
0
0

I've been playing around with Xamarin.Forms (using the PCL project template), and ran into the following issue.

var food = new Button { Text = "Food" };

Task.Run(async () =>
{
    Debug.WriteLine("starting a delay");
    await Task.Delay(1000);
    food.BackgroundColor = Color.Black;
    Debug.WriteLine("done");
});

This sample code just freezes on the Task.Delay forever. If I try to change the await for ContinueWith like the following it will crash the compiler

await Task.Delay(1000).ContinueWith(() => Debug.WriteLine("done delaying"));

with the following error message https://gist.github.com/darthdeus/75718d98fc2b5635b48f. Am I doing something wrong? Should I even be using Async/await in the PCL? Or should I just use the shared library instead?


Viewing all articles
Browse latest Browse all 58056

Trending Articles