Enable CA1837: Use 'Environment.ProcessId' (#14063)
https://docs.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1837
This commit is contained in:
parent
8148968546
commit
5c874207ec
|
@ -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
|
||||
|
|
|
@ -974,7 +974,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
}
|
||||
|
||||
// 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;
|
||||
|
@ -1214,7 +1214,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
|
||||
try
|
||||
{
|
||||
if (Process.GetCurrentProcess().Id == SafeGetProcessId(process))
|
||||
if (Environment.ProcessId == SafeGetProcessId(process))
|
||||
{
|
||||
_shouldKillCurrentProcess = true;
|
||||
continue;
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace System.Management.Automation
|
|||
{
|
||||
if (!this._processId.HasValue)
|
||||
{
|
||||
this._processId = (uint)System.Diagnostics.Process.GetCurrentProcess().Id;
|
||||
this._processId = (uint)Environment.ProcessId;
|
||||
}
|
||||
|
||||
return this._processId.Value;
|
||||
|
|
|
@ -511,7 +511,7 @@ namespace System.Management.Automation.Host
|
|||
Environment.MachineName,
|
||||
Environment.OSVersion.VersionString,
|
||||
string.Join(" ", Environment.GetCommandLineArgs()),
|
||||
System.Diagnostics.Process.GetCurrentProcess().Id,
|
||||
Environment.ProcessId,
|
||||
versionInfoFooter.ToString().TrimEnd());
|
||||
}
|
||||
|
||||
|
|
|
@ -377,7 +377,7 @@ namespace Microsoft.PowerShell.Commands
|
|||
|
||||
private void VerifyProcess(Process process)
|
||||
{
|
||||
if (process.Id == Process.GetCurrentProcess().Id)
|
||||
if (process.Id == Environment.ProcessId)
|
||||
{
|
||||
ThrowTerminatingError(
|
||||
new ErrorRecord(
|
||||
|
|
|
@ -744,7 +744,7 @@ namespace System.Management.Automation.Remoting
|
|||
[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.
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace System.Management.Automation
|
|||
|
||||
// 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.
|
||||
|
|
Loading…
Reference in a new issue