From 8f3ce1ee2f11f756179717bd4b3a456f13f66788 Mon Sep 17 00:00:00 2001 From: Dynesshely Date: Wed, 19 Jun 2024 19:42:40 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20Fix(DebugService):=20Adapt=20to?= =?UTF-8?q?=20new=20`Csharpell.Core`=20package?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/DebugWindowViewModel.cs | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/KitX Dashboard/ViewModels/DebugWindowViewModel.cs b/KitX Dashboard/ViewModels/DebugWindowViewModel.cs index e88e3e9..f3db901 100644 --- a/KitX Dashboard/ViewModels/DebugWindowViewModel.cs +++ b/KitX Dashboard/ViewModels/DebugWindowViewModel.cs @@ -19,17 +19,14 @@ public DebugWindowViewModel() InitEvents(); } - public override void InitCommands() + public sealed override void InitCommands() { SubmitCodesCommand = ReactiveCommand.Create(SubmitCodes); CancelExecutionCommand = ReactiveCommand.Create(() => _cancellationTokenSource?.Cancel()); } - public override void InitEvents() - { - - } + public sealed override void InitEvents() { } internal void SubmitCodes(IDocument doc) { @@ -41,21 +38,27 @@ internal void SubmitCodes(IDocument doc) _cancellationTokenSource = tokenSource; - Task.Run(async () => - { - var result = await DebugService.ExecuteCodesAsync(code, tokenSource.Token); + Task.Run( + async () => + { + var result = await DebugService.ExecuteCodesAsync( + code, + cancellationToken: tokenSource.Token + ); - tokenSource.Dispose(); + tokenSource.Dispose(); - _cancellationTokenSource = null; + _cancellationTokenSource = null; - Dispatcher.UIThread.Invoke(() => - { - ExecutionResult = result ?? string.Empty; + Dispatcher.UIThread.Invoke(() => + { + ExecutionResult = result ?? string.Empty; - IsExecuting = false; - }); - }); + IsExecuting = false; + }); + }, + tokenSource.Token + ); } private string _executionResult = string.Empty;