自己做的c#任务管理器
DataTable dtprocc = null;//获取所有进程 private void button7_Click(object sender, EventArgs e) { Process[] processes; processes = Process.GetProcesses(); string str = ""; dtprocc = new DataTable(); dtprocc.Columns.Add("pid"); dtprocc.Columns.Add("name"); foreach (Process p in processes) { try { dtprocc.Rows.Add(new object[] { p.Id, p.ProcessName }); } catch (Exception ex) { } } dataGridView1.DataSource = dtprocc; }//结束选中进程 private void button8_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { Process[] arrP = Process.GetProcesses(); foreach (DataGridViewRow dd in dataGridView1.SelectedRows) { int tt = Convert.ToInt32(dd.Cells[0].Value); Process pp = arrP.FirstOrDefault(p => p.Id == tt); try { pp.Kill(); } catch (Exception ee) { } } } }
评论