我正在使用 Xamarin.forms
(PCL
),我需要每隔几秒刷新/更新内容页面及其数据。数据从 viewmodel
中的 API
检索。
page.xaml.cs
中是否有任何方法或处理程序可以定期调用Get Api
,例如:
methodRunPeriodically()
{
userdata = await UserService.GetUserasync(_UserViewModel.EmployeeId);
}
最佳答案
Xamarin.Forms 有一个用于启动计时器的 API,您可能会发现它对此很有用,已记录 here .
Device.StartTimer (TimeSpan.FromSeconds(10), () => {
// If you want to update UI, make sure its on the on the main thread.
// Otherwise, you can remove the BeginInvokeOnMainThread
Device.BeginInvokeOnMainThread(() => methodRunPeriodically());
return shouldRunAgain;
});
关于c# - 每隔几秒自动刷新或更新内容页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41574642/