Hey I have an rather specific issue.
I am building an metronom, and this metronom also shows boxes, which will change their color in the given tact in bpm. the highest possible bpm is 400bpm with 4/4 beats. that means the fastest change of color should happen every: 37,5 ms.
The change of color will last some milliseconds.
Until now i tried to realize that with a timer:
timer = new System.Timers.Timer() { AutoReset = true, SynchronizingObject = null };
private async void timer1_Elapsed(object sender, ElapsedEventArgs e)
{
boxViewLast = (BoxView)beatDisplay.Children[(int)lastI];
boxView = (BoxView)beatDisplay.Children[(int)i];
boxViewLast.Color = boxColor;
boxView.Color = transColor;
await Task.Delay((int)BeatMilliseconds);
boxView.Color = boxColor;
lastI = i;
i++;
if (i >= numOfChildren)
{
i = 0;
}
timer.AutoReset = Tempo == 1 && Play;
}
But in the UI I see a flickering some times if the color is changing fast and sometimes it is not even changing. I guess that resources are getting blocked and so the change can not be fullfilled in the given time. Is there a way to have UI change async and very performant? But I also need a very pricise timer