Environment.ProcessId
instead of Process.GetCurrentProcess().Id
CS-P1002Using 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
.
var pid = Process.GetCurrentProcess().Id;
var pid = Environment.ProcessId;