如何在Xamarin中添加计时器? [英] How do I add a timer in Xamarin?
本文介绍了如何在Xamarin中添加计时器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我需要有一个计时器,从60秒开始倒计时.我是Xamarin的新手,也不知道它接受什么.它将在Android中使用.
So I need to have a timer to count down from 60 seconds. I am new to Xamarin and have no idea what it accepts. It will be used in Android.
关于如何开始的任何建议?
Any suggestions on how to start?
您可以使用 System.Timers.Timer
吗?
推荐答案
您可以使用System.Threading.Timer类,该类记录在Xamarin文档中:
You can use the System.Threading.Timer class, which is documented in the Xamarin docs: https://developer.xamarin.com/api/type/System.Threading.Timer/
或者,对于Xamarin.Forms,您可以通过Device类访问跨平台计时器:
Alternatively, for Xamarin.Forms, you have access to a cross-platform Timer via the Device class:
Device.StartTimer(TimeSpan.FromSeconds(1), () =>
{
// called every 1 second
// do stuff here
return true; // return true to repeat counting, false to stop timer
});
这篇关于如何在Xamarin中添加计时器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文