1- using Microsoft . UI . Xaml ;
1+ using CollapseLauncher . Extension ;
2+ using Microsoft . UI . Xaml ;
23using Microsoft . UI . Xaml . Media . Animation ;
34using System ;
45using System . Threading ;
@@ -22,16 +23,28 @@ private async void RestartTimer(double newDurationSeconds, int delayBeforeStartM
2223 {
2324 try
2425 {
25- DisposeAndDeregisterTimer ( ) ;
26- if ( ! IsLoaded || newDurationSeconds == 0 )
26+ if ( ! IsLoaded ||
27+ ! _isTemplateLoaded ||
28+ newDurationSeconds == 0 )
29+ {
30+ if ( newDurationSeconds == 0 )
31+ {
32+ _countdownProgressBar . Value = 0 ;
33+ }
34+ DisposeAndDeregisterTimer ( ) ;
35+
36+ return ;
37+ }
38+
39+ if ( _timerStoryboard != null )
2740 {
2841 return ;
2942 }
3043
3144 _countdownProgressBar . Minimum = 0 ;
3245 _countdownProgressBar . Maximum = 1 ;
3346
34- _timerStoryboard = new Storyboard ( ) ;
47+ Interlocked . Exchange ( ref _timerStoryboard , new Storyboard ( ) ) ;
3548 DoubleAnimation animation = new ( )
3649 {
3750 Duration = new Duration ( TimeSpan . FromSeconds ( newDurationSeconds ) ) ,
@@ -73,6 +86,7 @@ async void TimerStoryboardOnCompleted(object? sender, object e)
7386 VisualStateManager . GoToState ( this , StateNameCountdownProgressBarFadeOut , true ) ;
7487 await Task . Delay ( 500 ) ;
7588
89+ DisposeAndDeregisterTimer ( ) ;
7690 ItemIndex ++ ;
7791 }
7892 catch ( Exception ex )
@@ -82,16 +96,6 @@ async void TimerStoryboardOnCompleted(object? sender, object e)
8296 }
8397 }
8498
85- private void DisposeAndDeregisterTimer ( )
86- {
87- if ( ! _isTemplateLoaded )
88- {
89- return ;
90- }
91-
92- Interlocked . Exchange ( ref _timerStoryboard , null ) ? . Stop ( ) ;
93- }
94-
9599 /// <summary>
96100 /// Stops the slideshow countdown timer.
97101 /// </summary>
@@ -111,5 +115,20 @@ public void ResumeSlideshow()
111115 _timerStoryboard ? . Resume ( ) ;
112116 }
113117
118+ /// <summary>
119+ /// Resets the slideshow countdown timer.
120+ /// </summary>
121+ public void ResetSlideshow ( )
122+ {
123+ _timerStoryboard ? . Seek ( TimeSpan . FromSeconds ( 0 ) ) ;
124+ }
125+
126+ private void DisposeAndDeregisterTimer ( )
127+ {
128+ Storyboard ? oldStoryboard = Interlocked . Exchange ( ref _timerStoryboard , null ) ;
129+ oldStoryboard ? . Stop ( ) ;
130+ oldStoryboard ? . Children ? . Clear ( ) ;
131+ }
132+
114133 #endregion
115134}
0 commit comments