Environment.ProcessPath
to fetch process path instead of Process.GetCurrentProcess().MainModule.FileName
CS-P1013You 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
.
var procPath = Process.GetCurrentProcess().MainModule.FileName;
var procPath = Environment.ProcessPath;