Xamarin Forms中的后台计时器[PCL]

时间:2017-09-09 15:18:40

标签: c# android ios xamarin cross-platform

这是Xamarin Forms中可能的后台计时器吗?

我有三个按钮开始/暂停/停止和计时器文本,用于在我的应用程序中显示计时器。

当用户点击开始按钮时,我想启动计时器。一段时间后,用户将关闭应用程序,但计时器应在后台运行,直到停止按钮单击。

我希望每分钟都将lat日志发送到服务器,即使应用已关闭

1 个答案:

答案 0 :(得分:0)

private void OnStartbuttonClicked(object sender, EventArgs e)
    {
        // Save the Time, when the Timer starts
    }

    private void OnStopbuttonClicked(object sender, EventArgs e)
    {
        DateTime starttime = DateTime.Parse("String with the Time, when the Timer starts");
        DateTime endTime = DateTime.Now;


        TimeSpan difference = endTime - starttime;

        // difference ist the time of the timer
    }

希望对您有帮助

相关问题