更新时间:2022-12-26 13:19:10
您可以使用 Device.StartTimer(TimeSpan minutes)
方法启动后台任务,该任务将在给定的时间跨度后重复.这是一个代码示例:
You can use the Device.StartTimer(TimeSpan minutes)
method to start a background task that will repeat after the given time span. Here is a code example:
var minutes = TimeSpan.FromMinutes (3);
Device.StartTimer (minutes, () => {
// call your method to check for notifications here
// Returning true means you want to repeat this timer
return true;
});
这包含在 Xamarin Forms 中,因此您不需要任何特定于平台的逻辑.
This is included with Xamarin Forms, so you don't need any platform specific logic.