From 1355753e412004d9d576ddc0af8e6c62e19ecbf4 Mon Sep 17 00:00:00 2001 From: hsc Date: Mon, 14 Sep 2026 13:59:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=B0=83=E7=94=A8=E6=96=B9=E9=80=82?= =?UTF-8?q?=E9=85=8DConcurrentDictionary=EF=BC=88Add=E2=86=92TryAdd?= =?UTF-8?q?=E3=80=81Remove=E2=86=92TryRemove=EF=BC=89=EF=BC=8C=E4=B8=8EACP?= =?UTF-8?q?=20P0=E6=8F=90=E4=BA=A4=E5=AF=B9=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ADP/ViewModels/ShellViewModel.cs | 2 +- .../ViewModels/AutomatedTestingViewModel.cs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ADP/ViewModels/ShellViewModel.cs b/ADP/ViewModels/ShellViewModel.cs index f7e6103..dd710bb 100644 --- a/ADP/ViewModels/ShellViewModel.cs +++ b/ADP/ViewModels/ShellViewModel.cs @@ -208,7 +208,7 @@ namespace ADP.ViewModels SilenceBuzzerCommand = new AsyncDelegateCommand(SilenceBuzzer); GoBackCommand = new DelegateCommand(OnGoBack); - _globalInfo.ContextDic.Add("default", new ScopedContext()); + _globalInfo.ContextDic.TryAdd("default", new ScopedContext()); _eventAggregator.GetEvent().Subscribe(() => { diff --git a/MainModule/ViewModels/AutomatedTestingViewModel.cs b/MainModule/ViewModels/AutomatedTestingViewModel.cs index 0b586a0..9abf25e 100644 --- a/MainModule/ViewModels/AutomatedTestingViewModel.cs +++ b/MainModule/ViewModels/AutomatedTestingViewModel.cs @@ -217,10 +217,10 @@ namespace MainModule.ViewModels (LogAreaVM as IDisposable)?.Dispose(); (ParametersManagerVM as IDisposable)?.Dispose(); - _globalInfo.ContextDic?.Remove(TestStatus); - _globalInfo.StepRunningDic?.Remove(TestStatus); - _globalInfo.ConfigDic?.Remove(TestStatus); - _globalInfo.ScopeDic?.Remove(TestStatus); + _globalInfo.ContextDic?.TryRemove(TestStatus, out _); + _globalInfo.StepRunningDic?.TryRemove(TestStatus, out _); + _globalInfo.ConfigDic?.TryRemove(TestStatus, out _); + _globalInfo.ScopeDic?.TryRemove(TestStatus, out _); } catch (Exception ex) { @@ -275,10 +275,10 @@ namespace MainModule.ViewModels if (navigationContext.Parameters.ContainsKey("Name")) { TestStatus = navigationContext.Parameters.GetValue("Name"); - _globalInfo.ContextDic.Add(TestStatus, _scopedContext); - _globalInfo.StepRunningDic.Add(TestStatus, _stepRunning); - _globalInfo.ScopeDic.Add(TestStatus, _scope); - _globalInfo.ConfigDic.Add(TestStatus, _systemConfig); + _globalInfo.ContextDic.TryAdd(TestStatus, _scopedContext); + _globalInfo.StepRunningDic.TryAdd(TestStatus, _stepRunning); + _globalInfo.ScopeDic.TryAdd(TestStatus, _scope); + _globalInfo.ConfigDic.TryAdd(TestStatus, _systemConfig); if(_systemConfig.DefaultProgramFilePath != null&&File.Exists(_systemConfig.DefaultProgramFilePath)) { var filePath = _systemConfig.DefaultProgramFilePath;