0

我需要一些帮助,在我正在创建的程序中!我有一个简单的任务管理器,我可以在其中杀死一个进程!但是,我需要它,所以我可以杀死多个进程,被卡住了几天,有点不确定如何杀死多个进程。谁能给我任何建议?

通过多个进程,我并不是说只是将更多进程放在firefox旁边,我的意思是从listview或sql加载多个进程?

到目前为止,这是我的代码。我在想也许可以将进程保存到 sql,然后将它们加载到火狐所在的位置?

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
  }
}
4

1 回答 1

3
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
    }
}
于 2013-05-20T09:59:01.710 回答