C#编程应用--进程管理

http://www.cnblogs.com/dzone/archive/2011/09/28/2194909.html

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Diagnostics;using System.Threading; namespace ProcessExample { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void buttonStart_Click(object sender, EventArgs e) { process1.StartInfo.FileName = "notepad.exe"; //启动Notepad.exe进程. process1.Start(); } private void buttonStop_Click(object sender, EventArgs e) { //创建新的Process组件的数组,并将它们与指定的进程名称(Notepad)的所有进程资源相关联. Process[] myprocesses; myprocesses = Process.GetProcessesByName("Notepad"); foreach (Process instance in myprocesses) { //设置终止当前线程前等待1000毫秒 instance.WaitForExit(1000); instance.CloseMainWindow(); } } private void buttonView_Click(object sender, EventArgs e) { listBox1.Items.Clear(); //创建Process类型的数组,并将它们与系统内所有进程相关联 Process[] processes; processes = Process.GetProcesses(); foreach (Process p in processes) { //Idle指显示CPU空闲率的进程名称 //由于访问Idle的StartTime会出现异常,所以将其排除在外 if (p.ProcessName != "Idle") { //将每个进程名和进程开始时间加入listBox1中 this.listBox1.Items.Add( string.Format("{0,-30}{1:h:m:s}", p.ProcessName, p.StartTime)); } } } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值