Click here to Skip to main content
14,740,820 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a windows form to start and stop a process.
But even after stopping the desired process, on start- its showing a error message like "Already running".

What I have tried:

foreach (Process proc in Process.GetProcessesByName("processName"))
            {
                proc.Kill();
            }
Posted
Updated 13-Jan-21 9:14am

1 solution

Start here: Process.Kill Method (System.Diagnostics) | Microsoft Docs[^] and read what it says.
For example:
 Note

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.

 Note

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.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900