Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ dotnet_diagnostic.CA1835.severity = suggestion
dotnet_diagnostic.CA1836.severity = warning

# CA1837: Use 'Environment.ProcessId'
dotnet_diagnostic.CA1837.severity = suggestion
dotnet_diagnostic.CA1837.severity = warning

# CA1838: Avoid 'StringBuilder' parameters for P/Invokes
dotnet_diagnostic.CA1838.severity = silent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ protected override void ProcessRecord()
}

// It cannot wait on itself
if (process.Id.Equals(System.Diagnostics.Process.GetCurrentProcess().Id))
if (process.Id.Equals(Environment.ProcessId))
{
WriteNonTerminatingError(process, null, ProcessResources.WaitOnItself, "WaitOnItself", ErrorCategory.ObjectNotFound);
continue;
Expand Down Expand Up @@ -1214,7 +1214,7 @@ protected override void ProcessRecord()

try
{
if (Process.GetCurrentProcess().Id == SafeGetProcessId(process))
if (Environment.ProcessId == SafeGetProcessId(process))
{
_shouldKillCurrentProcess = true;
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public uint ProcessId
{
if (!this._processId.HasValue)
{
this._processId = (uint)System.Diagnostics.Process.GetCurrentProcess().Id;
this._processId = (uint)Environment.ProcessId;
}

return this._processId.Value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ private void LogTranscriptHeader(System.Management.Automation.Remoting.PSSenderI
Environment.MachineName,
Environment.OSVersion.VersionString,
string.Join(" ", Environment.GetCommandLineArgs()),
System.Diagnostics.Process.GetCurrentProcess().Id,
Environment.ProcessId,
versionInfoFooter.ToString().TrimEnd());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ private Process GetProcessByName(string name)

private void VerifyProcess(Process process)
{
if (process.Id == Process.GetCurrentProcess().Id)
if (process.Id == Environment.ProcessId)
{
ThrowTerminatingError(
new ErrorRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ private void WaitForConnection()
[SuppressMessage("Microsoft.Reliability", "CA2001:AvoidCallingProblematicMethods", MessageId = "System.Runtime.InteropServices.SafeHandle.DangerousGetHandle")]
private void ProcessListeningThread(object state)
{
string processId = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture);
string processId = Environment.ProcessId.ToString(CultureInfo.InvariantCulture);
string appDomainName = NamedPipeUtils.GetCurrentAppDomainName();

// Logging.
Expand Down
2 changes: 1 addition & 1 deletion src/System.Management.Automation/utils/PsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ internal static ProcessModule GetMainModule(Process targetProcess)

// Cache of the current process' parentId
private static int? s_currentParentProcessId;
private static readonly int s_currentProcessId = Process.GetCurrentProcess().Id;
private static readonly int s_currentProcessId = Environment.ProcessId;

/// <summary>
/// Retrieve the parent process of a process.
Expand Down