diff --git a/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs b/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs index e3c58c6673..39698e6ecb 100644 --- a/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs +++ b/src/Windows/Avalonia.Win32.Automation/AutomationNode.cs @@ -62,6 +62,8 @@ namespace Avalonia.Win32.Automation private readonly int[] _runtimeId; + private static readonly int s_pid = GetProcessId(); + public AutomationNode(AutomationPeer peer) { _runtimeId = new int[] { 3, GetHashCode() }; @@ -136,7 +138,7 @@ namespace Avalonia.Win32.Automation UiaPropertyId.LocalizedControlType => InvokeSync(() => Peer.GetLocalizedControlType()), UiaPropertyId.Name => InvokeSync(() => Peer.GetName()), UiaPropertyId.HelpText => InvokeSync(() => Peer.GetHelpText()), - UiaPropertyId.ProcessId => Process.GetCurrentProcess().Id, + UiaPropertyId.ProcessId => s_pid, UiaPropertyId.RuntimeId => _runtimeId, _ => null, }; @@ -355,5 +357,15 @@ namespace Avalonia.Win32.Automation _ => UiaControlTypeId.Custom, }; } + + private static int GetProcessId() + { +#if NET6_0_OR_GREATER + return Environment.ProcessId; +#else + using var proccess = Process.GetCurrentProcess(); + return proccess.Id; +#endif + } } }