Browse Source

Optimization for Process.GetCurrentProcess() in Avalonia.Win32.Automation (#17422)

* Use Environment.ProcessId instead of Process.GetCurrentProcess().Id

* revert override of GetPropertyValue

* apply suggestions from review
pull/17442/head
Easley 1 year ago
committed by GitHub
parent
commit
bde82e69b5
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 14
      src/Windows/Avalonia.Win32.Automation/AutomationNode.cs

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

Loading…
Cancel
Save