From 11fe48ea9a1e0bd2a98320371cd942ec0570ccd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Chsc=E2=80=9D?= <“huangsucan@kaiyili-lab.com”> Date: Thu, 10 Sep 2026 14:20:55 +0800 Subject: [PATCH] =?UTF-8?q?P0:=20GlobalInfo=20=E5=9B=9B=E4=B8=AA=20Diction?= =?UTF-8?q?ary=20=E6=94=B9=E4=B8=BA=20ConcurrentDictionary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ACP/ViewModels/ShellViewModel.cs | 2 +- .../ViewModels/AutomatedTestingViewModel.cs | 16 ++++++++-------- UIShare/GlobalVariable/GlobalInfo.cs | 8 ++++---- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ACP/ViewModels/ShellViewModel.cs b/ACP/ViewModels/ShellViewModel.cs index a49621e..4746303 100644 --- a/ACP/ViewModels/ShellViewModel.cs +++ b/ACP/ViewModels/ShellViewModel.cs @@ -227,7 +227,7 @@ namespace ACP.ViewModels SettingChannelCommand = new AsyncDelegateCommand(SilenceBuzzer); SettingChannelCommand = new DelegateCommand(SettingChannel); 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 13b488f..89e23e0 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; diff --git a/UIShare/GlobalVariable/GlobalInfo.cs b/UIShare/GlobalVariable/GlobalInfo.cs index 01d911f..d9ef389 100644 --- a/UIShare/GlobalVariable/GlobalInfo.cs +++ b/UIShare/GlobalVariable/GlobalInfo.cs @@ -12,10 +12,10 @@ namespace UIShare.GlobalVariable public class GlobalInfo:BindableBase { public event EventHandler? ScopeChanged; - public Dictionary ContextDic { get; set; } - public Dictionary StepRunningDic { get; set; } - public Dictionary ConfigDic { get; set; } - public Dictionary ScopeDic { get; set; } + public ConcurrentDictionary ContextDic { get; set; } + public ConcurrentDictionary StepRunningDic { get; set; } + public ConcurrentDictionary ConfigDic { get; set; } + public ConcurrentDictionary ScopeDic { get; set; } /// 硬件指纹 → 设备实例的并发池,确保同一物理硬件全局只创建一个驱动实例。 public ConcurrentDictionary> HardwarePool { get; set; }