Process组件的使用

来源:互联网 发布:python基础教程廖雪峰 编辑:程序博客网 时间:2024/05/17 00:51
using System;using System.Diagnostics;using System.Windows.Forms;namespace Process组件{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();            this.Load+=new EventHandler(Form1_Load);            this.button1.Click+=new EventHandler(button1_Click);            this.button2.Click+=new EventHandler(button2_Click);        }        private void Form1_Load(object sender, EventArgs e)        {            process1.StartInfo.FileName = "notepad.exe";        }        private void button1_Click(object sender, EventArgs e)        {            process1.Start();        }        private void button2_Click(object sender, EventArgs e)        {            Process[] parr = Process.GetProcessesByName("Notepad");            foreach (Process p in parr)            {                p.CloseMainWindow();                p.WaitForExit(3000);                p.Close();            }        }    }}


原创粉丝点击