c# - Timer to show seconds, minutes and hours in iOS Xamarin -


i working on ios application in xamarin.

timer1 = new system.timers.timer(); timer1.interval = 1000;  //play.touchupinside += (sender,e)=> //{        timer1.enabled = true;        console.writeline("timer started");        timer1.elapsed += new elapsedeventhandler(ontimeevent); //} 

this have written in 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); // works!             });         })).start();     }      else     {         //adjust ui         new system.threading.thread(new system.threading.threadstart(() =>         {             invokeonmainthread(() =>             {                 starttimer.text = convert.tostring(e.signaltime.timeofday); // works!             });         })).start();          timer1.enabled = false;         console.writeline("timer stopped");     } } 

this event have called when clicked on button play. want method keep running time updated on label (starttimer.text) in ui. runnable interface use in android, have use in ios keep running?

use async - cleaner (no marshalling on main thread again!)

private int _duration = 0;  public async void starttimer() {     _duration = 0;      // tick every second while game in progress     while (_gameinprogress) {         await task.delay (1000);         _duration++;          string s = timespan.fromseconds(_duration).tostring(@"mm\:ss");         btntime.settitle (s, uicontrolstate.normal);     } } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -