diff --git a/Examples/UICatalog/Scenarios/Scrolling.cs b/Examples/UICatalog/Scenarios/Scrolling.cs index 6b14d755b..43776fa83 100644 --- a/Examples/UICatalog/Scenarios/Scrolling.cs +++ b/Examples/UICatalog/Scenarios/Scrolling.cs @@ -1,4 +1,6 @@ -namespace UICatalog.Scenarios; +#nullable enable + +namespace UICatalog.Scenarios; [ScenarioMetadata ("Scrolling", "Content scrolling, IScrollBars, etc...")] [ScenarioCategory ("Controls")] @@ -6,6 +8,8 @@ [ScenarioCategory ("Tests")] public class Scrolling : Scenario { + private static object? _progressTimer = null; + public override void Main () { Application.Init (); @@ -38,10 +42,6 @@ public class Scrolling : Scenario app.Add (demoView); - //// NOTE: This call to EnableScrollBar is technically not needed because the reference - //// NOTE: to demoView.HorizontalScrollBar below will cause it to be lazy created. - //// NOTE: The call included in this sample to for illustration purposes. - //demoView.EnableScrollBar (Orientation.Horizontal); var hCheckBox = new CheckBox { X = Pos.X (demoView), @@ -52,10 +52,6 @@ public class Scrolling : Scenario app.Add (hCheckBox); hCheckBox.CheckedStateChanged += (sender, args) => { demoView.HorizontalScrollBar.Visible = args.Value == CheckState.Checked; }; - //// NOTE: This call to EnableScrollBar is technically not needed because the reference - //// NOTE: to demoView.HorizontalScrollBar below will cause it to be lazy created. - //// NOTE: The call included in this sample to for illustration purposes. - //demoView.EnableScrollBar (Orientation.Vertical); var vCheckBox = new CheckBox { X = Pos.Right (hCheckBox) + 3, @@ -96,8 +92,6 @@ public class Scrolling : Scenario app.Add (progress); - var pulsing = true; - app.Initialized += AppOnInitialized; app.Unloaded += AppUnloaded; @@ -108,17 +102,25 @@ public class Scrolling : Scenario return; - void AppOnInitialized (object sender, EventArgs e) + void AppOnInitialized (object? sender, EventArgs e) { bool TimerFn () { progress.Pulse (); - return pulsing; + return _progressTimer is { }; } - Application.AddTimeout (TimeSpan.FromMilliseconds (200), TimerFn); + _progressTimer = Application.AddTimeout (TimeSpan.FromMilliseconds (200), TimerFn); + } + + void AppUnloaded (object? sender, EventArgs args) + { + if (_progressTimer is { }) + { + Application.RemoveTimeout (_progressTimer); + _progressTimer = null; + } } - void AppUnloaded (object sender, EventArgs args) { pulsing = false; } } } \ No newline at end of file