voglio eseguire il seguenteUtilizzando Thread.Sleep in Xamarin.Forms
MainPage = new ContentPage
{
Content = new StackLayout
{
Children =
{
new Button
{
Text = "Thread.Sleep",
Command = new Command(() =>
{
Thread.Sleep(1000);
MainPage.Animate("", x => MainPage.BackgroundColor = Color.FromRgb(x, x, x));
}),
},
new Button
{
Text = "Task.Run + Thread.Sleep",
Command = new Command(async() =>
{
await Task.Run(() => Thread.Sleep(1000));
MainPage.Animate("", x => MainPage.BackgroundColor = Color.FromRgb(x, x, x));
})
},
new Button
{
Text = "Device.StartTimer",
Command = new Command(() => Device.StartTimer(
TimeSpan.FromSeconds(1),
() =>
{
MainPage.Animate("", x => MainPage.BackgroundColor = Color.FromRgb(x, x, x));
return false;
})),
},
}
}
};
ho incluso System.Threading
e System.Threading.Tasks
, ma ho ancora ottenere
Il nome 'Discussione' non esiste nel contesto attuale.
This site suggerisce che Thread.Sleep
può essere utilizzato in Xamarin.Forms
. Ho questo in un progetto condiviso, non in un PCL.
'Thread.Sleep' dovrebbero essere evitati durante l'utilizzo di quasi tutti i framework di interfaccia utente (WinForms/WPF/Xamarin.Forms/Silverlight/...) poiché congela il thread dell'interfaccia utente e blocca l'interfaccia utente. –
È solo a scopo dimostrativo, ma grazie per l'aggiunta. – testing