易采站长站为您分析C#实现进程管理的启动和停止方法,以操作记事本程序为例,实例分析了C#针对进程操作的基本技巧,需要的朋友可以参考下
本文实例讲述了C#实现进程管理的启动和停止方法。。具体实现方法如下:
- using System; using System.Collections.Generic;
- using System.ComponentModel; using System.Data;
- using System.Drawing; using System.Text;
- using System.Windows.Forms; using System.IO;
- //引用命名空间 using System.Diagnostics;
- using System.Threading; namespace StartStopProcess
- { public partial class Form1 : Form
- { int fileIndex;
- string fileName = "Notepad.exe"; Process process1 = new Process();
- public Form1() {
- InitializeComponent(); //以详细列表方式显示
- listView1.View = View.Details; //参数含义:列名称,宽度(像素),水平对齐方式
- listView1.Columns.Add("进程ID", 70, HorizontalAlignment.Left); listView1.Columns.Add("进程名称", 70, HorizontalAlignment.Left);
- listView1.Columns.Add("占用内存", 70, HorizontalAlignment.Left); listView1.Columns.Add("启动时间", 70, HorizontalAlignment.Left);
- listView1.Columns.Add("文件名", 280, HorizontalAlignment.Left); }
- private void buttonStart_Click(object sender, EventArgs e) {
- string argument = Application.StartupPath + "myfile" + fileIndex + ".txt"; if (File.Exists(argument)==false)
- { File.CreateText(argument);
- } //设置要启动的应用程序名称及参数
- ProcessStartInfo ps = new ProcessStartInfo(fileName, argument); ps.WindowStyle = ProcessWindowStyle.Normal;
- fileIndex++; Process p = new Process();
- p.StartInfo = ps; p.Start();
- //等待启动完成,否则获取进程信息可能会失败 p.WaitForInputIdle();










