Environment.ProcessId
to fetch process ID instead of Process.GetCurrentProcess().Id
CS-P1012You can use GetCurrentProcess().Id
to access the running program's process ID. However, this is an expensive call as it first allocates a Process
instance which then needs to be disposed, all just to get the running program's process ID. An efficient alternative is to just use the static
field Environment.ProcessId
.
var procID = Process.GetCurrentProcess().Id;
var procID = Environment.ProcessId;