C#

C#

Made by DeepSource

Use Environment.ProcessId to fetch process ID instead of Process.GetCurrentProcess().Id CS-P1012

Performance
Major
Autofix

You 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.

Bad Practice

var procID = Process.GetCurrentProcess().Id;

Recommended

var procID = Environment.ProcessId;

Reference