DeepSource has joined Harness. Learn more
C# logoC#/
CS-P1002

Consider using `Environment.ProcessId` instead of `Process.GetCurrentProcess().Id`CS-P1002

Critical severityCritical
Performance categoryPerformance

Using Process.GetCurrentProcess().Id requires that an instance of Process be allocated to access the required Id. It then adds additional overhead, i.e., disposing of the Process instance. It is therefore suggested that you use the reliable and performant alternative Environment.ProcessId.

Bad Practice

var pid = Process.GetCurrentProcess().Id;
var pid = Environment.ProcessId;

Reference