C#计算机进程管理工具,根据CPU结束相应进程
2012-12-18 17:56
411 查看
C#计算机进程管理工具,根据CPU变化结束相应进程(附源码打包下载)
2012-12-18 11:58 by 苏飞-C#.Net, 681 阅读, 7 评论, 收藏, 编辑C#计算机进程管理工具,根据CPU结束相应进程
这个工具是当CPU达到我们设置的相应值时,会自动结束设置好的进程。
先来看看界面吧
源码下载:
http://files.cnblogs.com/sufei/startName.rar
好了我们一下来看看代码吧,具体的我就不多说了,代码很简单,很容易看明白,如果确实有不明白的地方
要吧直接回复提问,
上代码
/// <summary> /// 更新网站:<a href=\"http://www.cckan.net/thread-1791-1-1.html\" target=\"_blank\">http://www.cckan.net/thread-1791-1-1.html</a> /// </summary> 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 startName { public partial class Form1 : Form { string cpu = string.Empty; string info = string.Empty; double cpuMax = 0; string ProcessName = ""; PerformanceCounter MainPC = new PerformanceCounter();//性能计数器 Process[] p = null; PerformanceCounter ChPC = new PerformanceCounter(); public Form1() { InitializeComponent(); } //开始执行 private void button1_Click(object sender, EventArgs e) { try { panel1.Enabled = false; timer1.Enabled = true; try { //设置一下执行的参数 timer1.Interval = 1000 * Convert.ToInt32(textBox4.Text.Trim()); } catch (Exception) { timer1.Interval = 1000 * 5; } MainPC.CategoryName = "Processor";//指定获取计算机进程信息如果传Processor参数代表查询计算机CPU MainPC.CounterName = "% Processor Time";//占有率 //如果pp.CategoryName="Processor",那么你这里赋值这个参数 pp.InstanceName = "_Total"代表查询本计算机的总CPU。 MainPC.InstanceName = "_Total";//指定进程 MainPC.MachineName = "."; cpuMax = Convert.ToDouble(textBox1.Text.Trim()); ProcessName = textBox2.Text.Trim(); p = System.Diagnostics.Process.GetProcessesByName(ProcessName); textBox3.Text += textBox2.Text + "进程数:" + p.Length.ToString() + "\r\n"; } catch (Exception) { timer1.Enabled = false; panel1.Enabled = true; } } private void timer1_Tick(object sender, EventArgs e) { try { double dcpu = Math.Round(MainPC.NextValue(), 2); label3.Text = "当前计算机CPU使用率:" + dcpu; textBox3.ScrollToCaret(); if (dcpu > cpuMax) { int le = 0; int num = 0; le = p.Length; for (int i = 0; i < le; i++) { textBox3.ScrollToCaret(); p.Kill(); num++; } textBox3.Text += DateTime.Now.ToString() + " Cpu:" + dcpu.ToString() + " 成功清理:" + num.ToString() + "个进程\r\n"; } } catch (Exception ex) { textBox3.Text += "出现问题:" + ex.Message.Trim() + "\r\n"; } } private void Form1_Load(object sender, EventArgs e) { } private void timer2_Tick(object sender, EventArgs e) { p = System.Diagnostics.Process.GetProcessesByName(ProcessName); } } }
其实这咱种工具还是很好用的,放在服务器上,如果电脑Cpu过高的话是可以直接维护的,
不用人工的再去处理了
不知道大家有没有这种情况,这是我在我服务器是用的一个小工具,给大家分享一下。希望大家喜欢
代码里面主要是运用了一些进程相关的操作方法,还有一些关于Cpu统计的一些方式。
好了就这样吧,具体的大家看代码吧,有什么建议请您回复我吧。期待大家的建议
相关文章推荐
- C#计算机进程管理工具,根据CPU变化结束相应进程(附源码打包下载)
- 基于C#.NET的--Windows进程管理工具
- C#导出Excel后无法结束相应进程的解决办法
- 根据端口号查找相应PID,从而在任务管理器中结束或查看相应进程
- 计算机原理学习(5)-- x86-16 CPU和内存管理
- Linux下取代top的进程管理工具 htop
- Linux性能优化 第四章 性能工具:特定进程CPU
- python 根据pid杀死相应进程
- Active Server Pages, ASP 0113 (0x80004005)超过了脚本运行的最长时间。可以为 Server.ScriptTimeOut 属性指定新值或更改 IIS 管理工具中的相应值来更改此限制
- goreman 多进程管理工具
- Python Supervisord 进程管理工具
- ProcessHacker工具中对于进程结束的具体实现代码:
- .NET(C#):获取进程的CPU使用状况
- 进程管理工具之ps top详解
- 'supervisor'进程管理工具配置与使用
- centos中进程管理工具
- C# 读取计算机CPU,HDD信
- linux2进程内存CPU管理笔记
- 微软XSD工具根据XSD文件生成的C#类中多余Specified属性问题
- 计算机操作系统——进程管理(4)