2

As shown in the picture below I would like to kill all those processes at once if I just press kill on the very top item. I would like to know how the task manager does it...Like how it finds the processes related and group them up like the picture those.

Picture 1

Picture 2

I have managed to kill the process by finding it by the names...but my application has a function of finding each other's processes and starts them if they are not started. I'm trying to kill both of them at once so none of the related application gets started again.

Sorry for the discomfort...I don't have enough reputation for a direct picture show.

Right now I have something like this but sometimes it kills two application fine but sometimes it keeps restarting...

string updaterProcess = "TimeKeeper.Updater";
Process currentProcess = Process.GetCurrentProcess();
currentProcess.Kill();

foreach (Process process in Process.GetProcesses())
{
    if (process.ProcessName.ToLower() == updaterProcess.ToLower())
    {
        process.Kill();
        currentProcess.Kill();

        process.Kill();
        currentProcess.Kill();

        process.Kill();
        currentProcess.Kill();

    }
}
Noor A Shuvo
  • 2,639
  • 3
  • 23
  • 48
  • I'm not sure but it might be help your problem. https://github.com/aspnet/Common/blob/ffb7c20fb22a31ac31d3a836a8455655867e8e16/shared/Microsoft.Extensions.Process.Sources/ProcessHelper.cs#L22 – Arphile Oct 05 '18 at 04:30
  • Arphile sorry but I've just got started with programming...How do I use that class? – BongJae Jeong Oct 05 '18 at 04:35
  • your foreach is taking let say some time to be executed , depends on how many processes u have running! So you need to try to put all of your processes in List and then in foreach loop you kill them all ! – J.Memisevic Oct 05 '18 at 04:36
  • J.Memisevic I just have to processes that needs to be executed. Sorry..but can you give me an example...? Just got started programming :( – BongJae Jeong Oct 05 '18 at 04:40
  • You are trying to kill the child processes as well. The following answer may help you: https://stackoverflow.com/a/5680096 – Subbu Oct 06 '18 at 02:47

1 Answers1

0
    string updaterProcess = "TimeKeeper.Updater";
    Process currentProcess = Process.GetCurrentProcess();
    List<Process> runningProcess=new List<Process>();
    foreach (Process process in Process.GetProcesses())
    {
        if (process.ProcessName.ToLower() == updaterProcess.ToLower())
        {

            runningProcess.Add(process);
        }
    }
     foreach (Process process in runningProcess)
    {


            process.Kill();


    }
    currentProcess.Kill();

Something like this.

J.Memisevic
  • 429
  • 4
  • 11