I have following method to animate a label for 20 seconds.
private async void Animate(object obj, PropertyChangedEventArgs e) { if (e.PropertyName == "ClassId") { VisualElement sender = obj as VisualElement; var parentAnimation = new Animation(); var fadeOutAnimation = new Animation(d => sender.Opacity = d, 1, 0, Easing.Linear); var fadeInAnimation = new Animation(d => sender.Opacity = d, 0, 1, Easing.Linear); parentAnimation.Add(0, 0.5, fadeOutAnimation); parentAnimation.Add(0.5, 1, fadeInAnimation); parentAnimation.Add(0, 0.5, fadeOutAnimation); parentAnimation.Add(0.5, 1, fadeInAnimation); parentAnimation.Add(0, 0.5, fadeOutAnimation); parentAnimation.Add(0.5, 1, fadeInAnimation); parentAnimation.Add(0, 0.5, fadeOutAnimation); parentAnimation.Add(0.5, 1, fadeInAnimation); parentAnimation.Commit(sender, "BlinkingVisualElement", 16 , 800, repeat: () => true); await Task.Delay(20000); parentAnimation.Commit(sender, "BlinkingVisualElement", 16, 800, repeat: () => false); } }
This method can get called multiple times within 20 seconds. It works fine and animates the label for full 20 seconds,if called one time and wait for 20 seconds before firing second call. I want it to animate 20 seconds whenever this method is fired.
Now what is happening
I called the method first time on
9:00:00 AM
It animates till 9:00:20
If i call the method second time on
9:00:12 AM
It still animates till 9:00:20 only(8 seconds only). I want it to animate till 9:00:32
Basically i want to reset the timer and show full 20 seconds animation whenever the event is fired