From fb5efd935f3200c017fb751a55c492c2cbc99a13 Mon Sep 17 00:00:00 2001 From: Flavien MICHALECZEK Date: Mon, 3 Feb 2025 05:43:13 +0100 Subject: [PATCH 1/2] Enable CA1837: Use 'Environment.ProcessId' --- src/System.Management.Automation/engine/SessionState.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/System.Management.Automation/engine/SessionState.cs b/src/System.Management.Automation/engine/SessionState.cs index e65f65ff385..61fd30c0ac1 100644 --- a/src/System.Management.Automation/engine/SessionState.cs +++ b/src/System.Management.Automation/engine/SessionState.cs @@ -337,10 +337,8 @@ internal void InitializeFixedVariables() this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $PID - Process currentProcess = Process.GetCurrentProcess(); - v = new PSVariable( - SpecialVariables.PID, - currentProcess.Id, + v = new PSVariable(SpecialVariables.PID, + Environment.ProcessId, ScopedItemOptions.Constant | ScopedItemOptions.AllScope, RunspaceInit.PIDDescription); this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); From 777bc29568558dadcc3112d533d75286dd0776e9 Mon Sep 17 00:00:00 2001 From: Ilya Date: Tue, 4 Feb 2025 11:43:18 +0500 Subject: [PATCH 2/2] Fix style --- src/System.Management.Automation/engine/SessionState.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/SessionState.cs b/src/System.Management.Automation/engine/SessionState.cs index 61fd30c0ac1..2ed9612f49c 100644 --- a/src/System.Management.Automation/engine/SessionState.cs +++ b/src/System.Management.Automation/engine/SessionState.cs @@ -337,7 +337,8 @@ internal void InitializeFixedVariables() this.GlobalScope.SetVariable(v.Name, v, asValue: false, force: true, this, CommandOrigin.Internal, fastPath: true); // $PID - v = new PSVariable(SpecialVariables.PID, + v = new PSVariable( + SpecialVariables.PID, Environment.ProcessId, ScopedItemOptions.Constant | ScopedItemOptions.AllScope, RunspaceInit.PIDDescription);