From 197af02c063ffa7944c1a60a816bbf52277a0d4f Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sat, 19 Feb 2022 14:12:00 +0100 Subject: [PATCH] fix(core): cancel control command cancellation token every time --- .../Commands/Control/ControlCommands.cs | 5 ++++- .../Commands/Control/TakeControlCommandHandler.cs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Core/NosSmooth.Core/Commands/Control/ControlCommands.cs b/Core/NosSmooth.Core/Commands/Control/ControlCommands.cs index 56e1e5b..274701b 100644 --- a/Core/NosSmooth.Core/Commands/Control/ControlCommands.cs +++ b/Core/NosSmooth.Core/Commands/Control/ControlCommands.cs @@ -198,7 +198,10 @@ public class ControlCommands try { - data.CancellationTokenSource.Cancel(); + if (!data.CancellationTokenSource.IsCancellationRequested) + { + data.CancellationTokenSource.Cancel(); + } } catch { diff --git a/Core/NosSmooth.Core/Commands/Control/TakeControlCommandHandler.cs b/Core/NosSmooth.Core/Commands/Control/TakeControlCommandHandler.cs index 07a894e..10ca2fd 100644 --- a/Core/NosSmooth.Core/Commands/Control/TakeControlCommandHandler.cs +++ b/Core/NosSmooth.Core/Commands/Control/TakeControlCommandHandler.cs @@ -49,5 +49,19 @@ public class TakeControlCommandHandler : ICommandHandler { return e; } + finally + { + if (!source.IsCancellationRequested) + { + try + { + source.Cancel(); + } + catch (Exception e) + { + // ignored + } + } + } } } \ No newline at end of file -- 2.48.1