Device.StartTimer(TimeSpan, Func<Boolean>) 方法

定义

使用设备时钟功能启动定期计时器。

public static void StartTimer(TimeSpan interval, Func<bool> callback);
static member StartTimer : TimeSpan * Func<bool> -> unit

参数

interval
System.TimeSpan

回叫的调用之间的间隔。

callback
System.Func<System.Boolean>

在计时器过期时要运行的操作。

注解

当回调返回 时 true,计时器将保持重复。

如果希望计时器内的代码在 UI 线程上交互 (例如设置标签的文本或显示警报) ,则应在表达式中 BeginInvokeOnMainThread 完成此操作,该表达式将嵌套在计时器内, (请参阅下面的) 。

Device.StartTimer (new TimeSpan (0, 0, 60), () =>
{
    // do something every 60 seconds
    Device.BeginInvokeOnMainThread (() => 
    {
      // interact with UI elements
    });
    return true; // runs again, or false to stop
});

适用于