From f41c5bdd6fd7a88f273470c2b428ce51d228f680 Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Sat, 28 Dec 2019 22:01:57 +0200 Subject: [PATCH] Used slightly better approach for executing stuff in the main thread --- Source/Core/Rendering/TextLabel.cs | 2 +- Source/Core/Windows/MainForm.cs | 49 +++++++++--------------------- 2 files changed, 16 insertions(+), 35 deletions(-) diff --git a/Source/Core/Rendering/TextLabel.cs b/Source/Core/Rendering/TextLabel.cs index db1a51a3..2de5c7f7 100755 --- a/Source/Core/Rendering/TextLabel.cs +++ b/Source/Core/Rendering/TextLabel.cs @@ -151,7 +151,7 @@ namespace CodeImp.DoomBuilder.Rendering { ff = new FontFamily(General.Settings.TextLabelFontName); } - catch (Exception e) + catch (Exception) { ff = General.MainWindow.Font.FontFamily; } diff --git a/Source/Core/Windows/MainForm.cs b/Source/Core/Windows/MainForm.cs index 98523b42..60c3a96b 100755 --- a/Source/Core/Windows/MainForm.cs +++ b/Source/Core/Windows/MainForm.cs @@ -282,11 +282,6 @@ namespace CodeImp.DoomBuilder.Windows //mxd. Hints hintsPanel = new HintsPanel(); hintsDocker = new Docker("hints", "Help", hintsPanel); - - // [ZZ] - InvokeTimer.Tick += new EventHandler(InvokeHandler); - InvokeTimer.Interval = 10; - InvokeTimer.Start(); } #endregion @@ -4117,37 +4112,23 @@ namespace CodeImp.DoomBuilder.Windows #region ================== Threadsafe updates - Timer InvokeTimer = new Timer(); - List InvokeActions = new List(); - - // this is actually InvokeTimer.Tick handler - void InvokeHandler(object sender, EventArgs e) - { - InvokeTimer.Stop(); - - List actions = null; - lock (InvokeActions) - { - if (InvokeActions.Count > 0) - { - actions = new List(); - actions.AddRange(InvokeActions); - } - } - - if (actions == null) - return; - - foreach (System.Action action in actions) - action(); - - InvokeTimer.Start(); - } - public void RunOnUIThread(System.Action action) { - if (!InvokeRequired) action(); - else lock (InvokeActions) InvokeActions.Add(action); + if (!InvokeRequired) + { + action(); + return; + } + + IAsyncResult result = null; + result = BeginInvoke(new System.Action(() => + { + action(); + // this may happen if exiting + while (result == null) + System.Threading.Thread.Sleep(1); + EndInvoke(result); + })); } public void UpdateStatus()