简体   繁体   English

如何杀死多个进程

[英]How to kill multiple processes

I need some help, Within a program I am creating! 我需要一些帮助,在我正在创建的程序中! I have a simple task manager where i can kill a single process! 我有一个简单的任务管理器,可以在其中杀死一个进程! However, i need it so I can kill multiple processes, been stuck a few days and a little unsure how to kill multiple processes. 但是,我需要它,所以我可以杀死多个进程,被困了几天,并且有点不确定如何杀死多个进程。 Can anyone give me any advice? 谁能给我任何建议?

By multiple processes, i dont mean just put more processes in along side firefox, i mean load multiple processes from a listview or sql? 通过多个进程,我不是说要在Firefox旁边放更多的进程,而是要从ListView或sql加载多个进程?

here is my code so far. 到目前为止,这是我的代码。 I was thinking maybe it was possible to save the processes to sql, and then load them in to where fire fox is? 我当时想也许可以将进程保存到sql,然后将其加载到fire fox所在的位置?

foreach (System.Diagnostics.Process pr in System.Diagnostics.Process.GetProcesses())//GETS PROCESSES
{
  if (pr.ProcessName == "firefox")//KILLS FIREFOX.....REMOVE FIREFOX.....CONNECT SAVED SQL PROCESSES IN HERE MAYBE??
  {
      pr.Kill(); //KILLS THE PROCESSES
  }
}
DataSet ds = new DataSet();// SQL STUFF
SqlConnection con = new SqlConnection(ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("SELECT ProcessName FROM ApplicationProcesses", con);
// since you start from SqlDataAdapter I'm continue from there..           
da.Fill(ds, "ProcessNames");
// get the process in the database to a array
string[] preocesArray = ds.Tables["ProcessNames"]
        .AsEnumerable()
        .Select(row => row.Field<string>("ProcessName"))
        .ToArray();

// kill the process if it is in the list 
var runningProceses = System.Diagnostics.Process.GetProcesses();
for (int i = 0; i < runningProceses.Length; i++)
{
    if (preocesArray.Contains(runningProceses[i].ProcessName))
    {
        runningProceses[i].Kill(); //KILLS THE PROCESSES
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM