C#

C#

Made by DeepSource

Use Environment.ProcessPath to fetch process path instead of Process.GetCurrentProcess().MainModule.FileName CS-P1013

Performance
Major
Autofix

You can use Process.GetCurrentProcess().MainModule.FileName to access the running program's path. 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 path. An efficient alternative is to just use the static field Environment.ProcessPath.

Bad Practice

var procPath = Process.GetCurrentProcess().MainModule.FileName;

Recommended

var procPath = Environment.ProcessPath;

Reference