From 45e3fa5f3ff7c6ec50c5a3a63517e20332f1bf58 Mon Sep 17 00:00:00 2001 From: Maximilien Noal Date: Tue, 23 Jan 2024 23:51:52 +0100 Subject: [PATCH] UI: Initialize timer once Signed-off-by: Maximilien Noal --- src/Spice86/ViewModels/MainWindowViewModel.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Spice86/ViewModels/MainWindowViewModel.cs b/src/Spice86/ViewModels/MainWindowViewModel.cs index 782767458..3442c07e6 100644 --- a/src/Spice86/ViewModels/MainWindowViewModel.cs +++ b/src/Spice86/ViewModels/MainWindowViewModel.cs @@ -54,6 +54,7 @@ public sealed partial class MainWindowViewModel : ViewModelBase, IPauseStatus, I [ObservableProperty] private Configuration _configuration; private bool _disposed; + private bool _renderingTimerInitialized; private bool _drawingSemaphoreSlimDisposed; private Thread? _emulatorThread; private bool _isSettingResolution; @@ -332,7 +333,11 @@ public void ShowColorPalette() { [RelayCommand] public void ResetTimeMultiplier() => TimeMultiplier = Configuration.TimeMultiplier; - private void InitializeRenderingThread() { + private void InitializeRenderingTimer() { + if (_renderingTimerInitialized) { + return; + } + _renderingTimerInitialized = true; _drawTimer.Elapsed += (_, _) => DrawScreen(); _drawTimer.Start(); } @@ -448,7 +453,7 @@ public void SetResolution(int width, int height) => _uiDispatcher.Post(() => { } } _isSettingResolution = false; - InitializeRenderingThread(); + InitializeRenderingTimer(); }, DispatcherPriority.MaxValue); public event EventHandler? RenderScreen;