Xamarin.Forms的System.Threading中不包含Timer [英] Timer doesn't contain in System.Threading at Xamarin.Forms

查看:99
本文介绍了Xamarin.Forms的System.Threading中不包含Timer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xamarin.Android中使用了System.Threading.Timer.

如何在Xamarin.Forms中使用相同的类? (我想从Xamarin.Forms中的Xamarin.Android转移我的项目)

How I can use the same class in Xamarin.Forms? (I want to transfer my project from Xamarin.Android in Xamarin.Forms)

public static System.Threading.Timer timer;
if (timer == null)
{
    System.Threading.TimerCallback tcb = MyMethod;
    timer = new System.Threading.Timer(tcb, null, 700, System.Threading.Timeout.Infinite);
}
else
{
    timer.Change(System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
    timer.Change(700, System.Threading.Timeout.Infinite);
}

推荐答案

System.Threading.Timer在PCL代码中不可用. 您可以按照以下说明使用Xamarin.Forms.Device.StartTimer方法: http://developer.xamarin.com/api/member/Xamarin.Forms.Device.StartTimer/

System.Threading.Timer is not available in PCL code. You can use the Xamarin.Forms.Device.StartTimer method instead as explained here: http://developer.xamarin.com/api/member/Xamarin.Forms.Device.StartTimer/

这篇关于Xamarin.Forms的System.Threading中不包含Timer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆