小编ayu*_*nia的帖子

计时器显示iOS Xamarin中的秒,分钟和小时

我正在开发Xamarin的iOS应用程序.

timer1 = new System.Timers.Timer();
timer1.Interval = 1000;

//Play.TouchUpInside += (sender,e)=>
//{
       timer1.Enabled = true;
       Console.WriteLine("timer started");
       timer1.Elapsed += new ElapsedEventHandler(OnTimeEvent);
//}
Run Code Online (Sandbox Code Playgroud)

这是我在viewdidload()中写的;

public void OnTimeEvent(object source, ElapsedEventArgs e)
{
    count++;
    Console.WriteLine("timer tick");
    if (count == 30)
    {
        timer1.Enabled = false;
        Console.WriteLine("timer finished");

        new System.Threading.Thread(new System.Threading.ThreadStart(() =>
        {
            InvokeOnMainThread(() =>
            {
                StartTimer.Text = Convert.ToString(e.SignalTime.TimeOfDay); // this works!
            });
        })).Start();
    }

    else
    {
        //adjust the UI
        new System.Threading.Thread(new System.Threading.ThreadStart(() =>
        {
            InvokeOnMainThread(() =>
            {
                StartTimer.Text = Convert.ToString(e.SignalTime.TimeOfDay); // this works!
            }); …
Run Code Online (Sandbox Code Playgroud)

c# timer xamarin.ios ios xamarin

2
推荐指数
1
解决办法
4518
查看次数

标签 统计

c# ×1

ios ×1

timer ×1

xamarin ×1

xamarin.ios ×1