i use timer , execute time, pause , stop.
has spent several days search how use in best way timer because, know, not exist timer directly unless create it.
so, followed these informations creating timer, using timespan, timercallback , stopwatch :
timer doesn't contain in system.threading @ xamarin.forms
https://developer.xamarin.com/api/namespace/system.timers/
https://developer.xamarin.com/api/type/system.diagnostics.stopwatch/
i think stopwatch best. , several manupulations, have wanted, problem time runs out every time press run button, when should press once on button.
with thread too, had done dis not change anything. not know why that.
and same datetime, time of datetime continues run while did not press button stop it.
if have idea avout it, thank in advance.
as said, think have would. need press 1 time button run chronometer instead of press everytime incrementation of time milliseconds milliseconds.
so, here chronotimer.cs :
class timerexpand { public int counter = 0; public system.threading.timer threadtimer; } public static void temps() { timerexpand t_expand = new timerexpand(); timercallback timerdelegate = new timercallback(gettime); system.threading.timer timer = new system.threading.timer(timerdelegate, t_expand, 0, 1000); t_expand.threadtimer = timer; } public static void gettime(object etat) { timerexpand t_expand = (timerexpand) etat; t_expand.counter++; } private datetime actualdate; public static stopwatch sw;
and on buttontimer_onclicked method :
actualdate = datetime.now; sw = new stopwatch(); sw.start(); labelchrono.text = string.format("{0:00}:{1:00}:{2:00}:{3:00}", sw.elapsed.hours, sw.elapsed.minutes, sw.elapsed.seconds, sw.elapsed.milliseconds); labeldate.text = datetime.now.tostring(); temps(); }