gpt4 book ai didi

xamarin - 每 X 时间运行一次后台任务

转载 作者:行者123 更新时间:2023-12-02 14:13:06 26 4
gpt4 key购买 nike

我想启动一项服务,该服务会在所有平台上偶尔检查是否有通知出现。有没有连接所有平台的nuget或者一些例子?

最佳答案

您可以使用 Device.StartTimer(TimeSpan 分钟) 方法启动后台任务,该任务将在给定时间跨度后重复。这是一个代码示例:

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 中,因此您不需要任何特定于平台的逻辑。

http://iosapi.xamarin.com/index.aspx?link=M%3AXamarin.Forms.Device.StartTimer(System.TimeSpan%2CSystem.Func%7BSystem.Boolean%7D)

关于xamarin - 每 X 时间运行一次后台任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30938008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com