修复了设备在启动和停止时的一些逻辑错误。

This commit is contained in:
2025-07-16 13:15:29 +08:00
parent b742067c39
commit 7e02255bdb
6 changed files with 479 additions and 343 deletions

View File

@@ -38,7 +38,8 @@ public partial class OpcUaImportDialogViewModel : ObservableObject
OpcUaNodes = new ObservableCollection<OpcUaNode>();
SelectedNodeVariables = new ObservableCollection<VariableData>();
// Automatically connect when the ViewModel is created
_ = Connect().ConfigureAwait(false);
ConnectCommand.Execute(null);
}
[RelayCommand]
@@ -49,7 +50,7 @@ public partial class OpcUaImportDialogViewModel : ObservableObject
// 断开现有连接
if (_session != null && _session.Connected)
{
_session.Close();
await _session.CloseAsync();
_session.Dispose();
_session = null;
}
@@ -69,7 +70,6 @@ public partial class OpcUaImportDialogViewModel : ObservableObject
catch (Exception ex)
{
IsConnected = false;
NlogHelper.Error($"连接 OPC UA 服务器失败: {EndpointUrl} - {ex.Message}", ex);
NotificationHelper.ShowError($"连接 OPC UA 服务器失败: {EndpointUrl} - {ex.Message}", ex);
}
}

View File

@@ -185,14 +185,14 @@ public partial class SettingViewModel : ViewModelBase
_connectionSettings.EnableOpcUaService = value;
OnPropertyChanged();
_connectionSettings.Save();
if (value)
{
_opcUaBackgroundService.StartService();
}
else
{
_opcUaBackgroundService.StopService();
}
// if (value)
// {
// _opcUaBackgroundService.StartService();
// }
// else
// {
// _opcUaBackgroundService.StopService();
// }
}
}
}