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; }