From c5219bd224bd2e54f728de1c52bb9c307275e62e Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Fri, 17 Jul 2020 22:54:30 +0200 Subject: [PATCH] Prevented an possible deadlock when moving devices in the surface editor --- src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs b/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs index f0698d57f..ec51011df 100644 --- a/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs +++ b/src/Artemis.UI.Shared/Controls/DeviceVisualizer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.IO; using System.Linq; +using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Media; @@ -29,6 +30,7 @@ namespace Artemis.UI.Shared.Controls private BitmapImage _deviceImage; private bool _subscribed; private ArtemisDevice _oldDevice; + private Task _lastRenderTask; public DeviceVisualizer() { @@ -209,11 +211,13 @@ namespace Artemis.UI.Shared.Controls private void RgbSurfaceOnUpdated(UpdatedEventArgs e) { - Dispatcher.Invoke(() => + _lastRenderTask?.Wait(); + + _lastRenderTask = Dispatcher.InvokeAsync(() => { if (ShowColors && Visibility == Visibility.Visible) Render(); - }); + }).Task; } private void Render()