Hi!
I'm trying to do a file-copy operation using the paths I get from enumerated processes. It works OK when I debug the program, adding a breakpoint at line-5 and stepping into the Copy method. But when I run it directly in VStudio or by double-clicking the exe, it gives an "System.IO.IOException" excetion. Anyone knows why?
if (MessageBox.Show("You Sure?", "!!", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
exePath = proc.MainModule.FileName.ToString();
proc.Kill();
File.Copy(Application.ExecutablePath, exePath, true);
}
}
Thanks!

Rajanikant HawaldarPosted Oct 1, 2022, 2:01 PM
test it
Rajanikant HawaldarPosted Oct 2, 2022, 8:25 AM
yeah you cannot be sure that Kill() even kills the process.
The Kill method executes asynchronously. After calling the Kill method, call the WaitForExit method to wait for the process to exit, or check the HasExited property to determine if the process has exited.
The WaitForExit method and the HasExited property do not reflect the status of descendant processes. When Kill(entireProcessTree: true) is used, WaitForExit and HasExited will indicate that exiting has completed after the given process exits, even if all descendants have not yet exited.
Kasun LeePosted Oct 2, 2022, 2:20 AM
@Raj Thanks mate, that works. Kill() probably needed a bit more time to release all the resouces.
Cheers!
Rajanikant HawaldarPosted Oct 1, 2022, 1:57 PM
"System.IO.IOException" exception type, but exceptions also have a message with more details, can you tell that