C#进程管理程序实现
2013-11-14 22:26
495 查看
运行效果图
部分代码如下:
部分代码如下:
#region 打开应用程序按钮事件处理程序 /// <summary> /// 打开应用程序按钮事件处理程序 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void open_Click(object sender, EventArgs e) { OpenFileDialog fd = new OpenFileDialog(); fd.FileName = ""; fd.Filter = "应用程序(*.exe)|*.exe"; fd.ShowDialog(); if(fd.FileName!="") { //设置启动的信息 ProcessStartInfo ps = new ProcessStartInfo(fd.FileName); temp = new Process(); temp.StartInfo = ps; temp.Start(); Thread.Sleep(1000); FreshDataGriedView(); } } #endregion #region 刷新进程表方法 /// <summary> /// 刷新进程表 /// </summary> private void FreshDataGriedView() { Process[] _temp = Process.GetProcesses(); dataGridView1.Rows.Clear(); foreach(Process temp in _temp){ int newRowIndex = dataGridView1.Rows.Add(); DataGridViewRow newRow = dataGridView1.Rows[newRowIndex]; newRow.Cells[0].Value=temp.Id; newRow.Cells[1].Value=temp.ProcessName; newRow.Cells[2].Value=string.Format("{0:###,##0.00}",temp.WorkingSet64/1024.0f/1024.0f); try{ newRow.Cells[3].Value=string.Format("{0}",temp.StartTime); newRow.Cells[4].Value=temp.MainModule.FileName; } catch{ newRow.Cells[3].Value=""; newRow.Cells[4].Value=""; } } } #endregion #region 刷新按钮的事件处理 /// <summary> /// 刷新按钮的事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void fresh_but_Click(object sender, EventArgs e) { FreshDataGriedView(); } #endregion #region 关闭进程按钮事件处理程序 /// <summary> /// 关闭进程按钮事件处理程序 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { //label1.Text = process_selceted_id.ToString(); try { //temp.Dispose(); temp.CloseMainWindow(); FreshDataGriedView(); } catch { MessageBox.Show("请选中一个进程","错误提示",MessageBoxButtons.OK); } } #endregion //行选中的事件 private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { try { //label1.Text = e.RowIndex.ToString() + "--" + dataGridView1.Rows[e.RowIndex].Cells[0].Value; process_selceted_id = Convert.ToInt16(dataGridView1.Rows[e.RowIndex].Cells[0].Value); temp = Process.GetProcessById(process_selceted_id); textbox_apand(); } catch { } } //显示进程信息 private void textbox_apand() { StringBuilder stringText = new StringBuilder(); stringText.AppendLine("进程ID:" + temp.Id); stringText.AppendLine("进程ID:"+temp.ProcessName); try { stringText.AppendLine(); ProcessModule m = temp.MainModule; stringText.AppendLine("文件名:"+m.FileName); stringText.AppendLine("版 本:"+m.FileVersionInfo.FileVersion); stringText.AppendLine("描 述:"+m.FileVersionInfo.FileDescription); stringText.AppendLine("语 言:"+m.FileVersionInfo.Language); } catch{ stringText.AppendLine("无法获取信息"); } this.textBox1.Text = stringText.ToString(); }
相关文章推荐
- C#通过接口与线程通信(捕获线程状态)介绍
- C#基础笔记——命名规范
- 有关 C# 命名参数和可选参数
- 编写C# Windows服务,用于杀死Zsd.exe进程
- C#中Hashtable的用法
- C#中virtual和abstract的区别
- C#通过接口与线程通信(捕获线程状态)介绍
- C#学习笔记之六:异常
- C# 求精简用一行代码完成的多项判断 重复赋值
- c# 操作xml题目
- C#学习记录二:高级数据存储方式
- C# 中Textbox 滚动到最后
- C#调用opencv
- C#学习笔记之五:集合
- 【C#】监视U盘的插入与拔出
- C#传递参数大集合
- c#调用语音功能
- 【C#】调用API
- C#3.0特性之列表对象的赋值更容易
- Emgu CV(OpenCV for C#)学习笔记(3)