using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace Start_and_Shutdown
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
TextBox box = new TextBox();
box.Multiline = true;
GetProcess();
}
private string GetProcess()
{
Process[] pres = Process.GetProcesses();
foreach (Process pre in pres)
{
listorder.Items.Add(pre.ProcessName);//获取进程的名称
}
return listorder.Text;
}
private void btnkill_Click(object sender, EventArgs e)
{
Process[] pres = Process.GetProcesses();
List<string> process = new List<string>();
foreach (Process pre in pres)
{
process.Add(pre.ProcessName );
}
foreach (Process pre in pres)
{
if(pre!=null&&!pre.HasExited)//判断该进程是否为空和进程是否结束
{
foreach (string s in process )
{
if(listorder .SelectedItem.ToString()==s)//判斷用戶選擇的ListBox中的項在進程中是否存在
{
DialogResult message = MessageBox.Show("是否干掉该进程?", "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (Convert.ToString(message) == "Yes")
{
pre.Kill();
return;
}
}
}
}
}
}
}
}
在ListBox列表中干不掉进程,怎么回事呢 ,大家帮忙看看代码有神马问题 |
|