| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4987 人关注过本帖
标题:[求助]C#获取每个进程的CPU利用率??
只看楼主 加入收藏
leona
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2006-11-20
收藏
 问题点数:0 回复次数:46 
[求助]C#获取每个进程的CPU利用率??
C#获取每个进程 CPU利用率
搜索更多相关主题的帖子: CPU利用率 进程 获取 
2006-11-26 00:16
leona
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2006-11-20
收藏
得分:0 
还有怎么关闭!!不能关闭的进程??
2006-11-26 09:29
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
Thread mythread;
mythread.Suspend()

飘过~~
2006-11-26 14:37
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
Process类
2006-11-26 17:32
leona
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2006-11-20
收藏
得分:0 
Thread mythread;
mythread.Suspend()
能说详细点吗??
2006-11-26 23:41
live41
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:67
帖 子:12442
专家分:0
注 册:2004-7-22
收藏
得分:0 
Process 类


不要再让我 repeat again 了,你搞清楚进程和线程的区别先。
2006-11-26 23:53
Jiawee
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-11-27
收藏
得分:0 

关闭线程..

2006-11-27 01:40
leona
Rank: 1
等 级:新手上路
帖 子:94
专家分:0
注 册:2006-11-20
收藏
得分:0 
C#获取每个进程 CPU利用率
Process 类
好像没有这个功能吧??
我说的是windows任务管理器里面的进程!!
我想实现的是有些木马关不掉我用c#把它关掉!!

现在的问题是kill()把某些进程还是关不掉!!
程序里没有每个进程的cpu利用率!!

希望高手详细解答一下!!

谢谢
2006-11-27 11:36
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 

[CODE]///获取任务管理器里的一些信息

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Runtime .InteropServices ;

namespace MemoryInfo
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox MemoryLoad;
private System.Windows.Forms.TextBox TotalPageFile;
private System.Windows.Forms.TextBox TotalPhys;
private System.Windows.Forms.TextBox TotalVirtual;
private System.Windows.Forms.TextBox AvailPageFile;
private System.Windows.Forms.TextBox AvailPhys;
private System.Windows.Forms.TextBox AvailVirtual;
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button1 = new System.Windows.Forms.Button();
this.MemoryLoad = new System.Windows.Forms.TextBox();
this.TotalPageFile = new System.Windows.Forms.TextBox();
this.TotalPhys = new System.Windows.Forms.TextBox();
this.TotalVirtual = new System.Windows.Forms.TextBox();
this.AvailPageFile = new System.Windows.Forms.TextBox();
this.AvailPhys = new System.Windows.Forms.TextBox();
this.AvailVirtual = new System.Windows.Forms.TextBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 192);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "刷新";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// MemoryLoad
//
this.MemoryLoad.Location = new System.Drawing.Point(8, 8);
this.MemoryLoad.Name = "MemoryLoad";
this.MemoryLoad.Size = new System.Drawing.Size(264, 21);
this.MemoryLoad.TabIndex = 1;
this.MemoryLoad.Text = "textBox1";
//
// TotalPageFile
//
this.TotalPageFile.Location = new System.Drawing.Point(8, 32);
this.TotalPageFile.Name = "TotalPageFile";
this.TotalPageFile.Size = new System.Drawing.Size(264, 21);
this.TotalPageFile.TabIndex = 2;
this.TotalPageFile.Text = "textBox1";
//
// TotalPhys
//
this.TotalPhys.Location = new System.Drawing.Point(8, 56);
this.TotalPhys.Name = "TotalPhys";
this.TotalPhys.Size = new System.Drawing.Size(264, 21);
this.TotalPhys.TabIndex = 3;
this.TotalPhys.Text = "textBox1";
//
// TotalVirtual
//
this.TotalVirtual.Location = new System.Drawing.Point(8, 80);
this.TotalVirtual.Name = "TotalVirtual";
this.TotalVirtual.Size = new System.Drawing.Size(264, 21);
this.TotalVirtual.TabIndex = 4;
this.TotalVirtual.Text = "textBox1";
//
// AvailPageFile
//
this.AvailPageFile.Location = new System.Drawing.Point(8, 104);
this.AvailPageFile.Name = "AvailPageFile";
this.AvailPageFile.Size = new System.Drawing.Size(264, 21);
this.AvailPageFile.TabIndex = 5;
this.AvailPageFile.Text = "textBox1";
//
// AvailPhys
//
this.AvailPhys.Location = new System.Drawing.Point(8, 128);
this.AvailPhys.Name = "AvailPhys";
this.AvailPhys.Size = new System.Drawing.Size(264, 21);
this.AvailPhys.TabIndex = 6;
this.AvailPhys.Text = "textBox1";
//
// AvailVirtual
//
this.AvailVirtual.Location = new System.Drawing.Point(8, 152);
this.AvailVirtual.Name = "AvailVirtual";
this.AvailVirtual.Size = new System.Drawing.Size(264, 21);
this.AvailVirtual.TabIndex = 7;
this.AvailVirtual.Text = "textBox1";
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(280, 221);
this.Controls.Add(this.AvailVirtual);
this.Controls.Add(this.AvailPhys);
this.Controls.Add(this.AvailPageFile);
this.Controls.Add(this.TotalVirtual);
this.Controls.Add(this.TotalPhys);
this.Controls.Add(this.TotalPageFile);
this.Controls.Add(this.MemoryLoad);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
[DllImport("kernel32")]
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
[StructLayout(LayoutKind.Sequential)]
public struct MEMORY_INFO
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}

private void button1_Click(object sender, System.EventArgs e)
{

MEMORY_INFO MemInfo;
MemInfo = new MEMORY_INFO();
GlobalMemoryStatus(ref MemInfo);
MemoryLoad.Text = MemInfo.dwMemoryLoad.ToString()+"%的内存正在使用";
TotalPhys.Text = "物理内存共有"+MemInfo.dwTotalPhys.ToString()+"字节";
AvailPhys.Text = "可使用的物理内存有"+MemInfo.dwAvailPhys.ToString()+"字节";
TotalPageFile.Text = "交换文件总大小为"+MemInfo.dwTotalPageFile.ToString()+"字节";
AvailPageFile.Text = "尚可交换文件大小为"+MemInfo.dwAvailPageFile.ToString()+"字节";
TotalVirtual.Text = "总虚拟内存有"+MemInfo.dwTotalVirtual.ToString()+"字节";
AvailVirtual.Text = "未用虚拟内存有"+MemInfo.dwAvailVirtual.ToString()+"字节";
}
private void Form1_Load(object sender, System.EventArgs e)
{
timer1.Enabled =true;
}
private void timer1_Tick(object sender, System.EventArgs e)
{
timer1.Enabled =false;
MEMORY_INFO MemInfo;
MemInfo = new MEMORY_INFO();
GlobalMemoryStatus(ref MemInfo);
MemoryLoad.Text = MemInfo.dwMemoryLoad.ToString()+"%的内存正在使用";
TotalPhys.Text = "物理内存共有"+MemInfo.dwTotalPhys.ToString()+"字节";
AvailPhys.Text = "可使用的物理内存有"+MemInfo.dwAvailPhys.ToString()+"字节";
TotalPageFile.Text = "交换文件总大小为"+MemInfo.dwTotalPageFile.ToString()+"字节";
AvailPageFile.Text = "尚可交换文件大小为"+MemInfo.dwAvailPageFile.ToString()+"字节";
TotalVirtual.Text = "总虚拟内存有"+MemInfo.dwTotalVirtual.ToString()+"字节";
AvailVirtual.Text = "未用虚拟内存有"+MemInfo.dwAvailVirtual.ToString()+"字节";
timer1.Enabled =true;
}
}
}[/CODE]


此号自封于2006年11月30日
2006-11-27 12:02
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 


你想实现这个目的需要了解
1:进程与线程的区别
2:如何获得任务管理器里的信息
3:如何控制进程的开始结束
你想要的功能论坛里有很多代码资源
好好搜索一下

此号自封于2006年11月30日
2006-11-27 12:03
快速回复:[求助]C#获取每个进程的CPU利用率??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.045313 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved