I struggle to understand the UI update process when I use the Xamarin forms timer.
I'm using the progressbar from Syncfusion and I want to animate it.
The interval is different from time to time (e.g. sometimes the progessbar should reload after 5 secondes, sometimes after 10).
I'm using
progress.SetProgress(100, (int)totalSec * 1000, Easing.Linear);
Device.StartTimer(TimeSpan.FromSeconds(1), TimerElapsed);
to invoke a Xamarin Forms Timer and to start the first animation.
In the method TimerElapsed(), I try to reset the progessbar to 0 if the interval has ended. After that, the animation should start again:
progressbar.SetProgress(0, 0, Easing.Linear);
progressbar.SetProgress(100, (int)totalSec * 1000, Easing.Linear);
However, the progessbar is not resetted. I debugged the application and realized that the UI is only updated after TimerElapsed is finished. I have the feeling that the first SetProgress() call is somehow overridden by the second call. Is that right or do I misunderstand the functionality? How can I rewrite the process to solve this problem?
And I would like to implement a Start / Stop button. At the moment I am calculating the current progress when the stop button is clicked and I set the progress value to it. However, this results in little "jumps" to the actual value. Is there an easier and more precise way to stop the animation?
Thank you for your help!