Using Unmanage Code in C#
http://www.codeguru.com/cs_syntax/Unmanage.html
http://www.codeguru.com/cs_syntax/Unmanage.html
解决方案 »
- winform如何在后台访问控件。
- 求个正则表达式!新手大家帮帮忙!
- 安装visual studio后关机显示explorer.exe无法关闭
- 一段 简单的delphi数据库查询代码 哪位仁兄帮我转为 C#的~~
- 比较两个a,b两个string[]中的记录,如果b没有a有,则删除a中的记录。求高效率方法
- DataGridView排序的问题(VB中测试成功)
- 求教:不能新建Excel.Application???
- C#里怎么实现链表,二叉树一类的数据结构
- 招聘.NET程序员
- 高分求助:如何通过编程实现在ad中为已经存在的用户添加邮箱。(分可以再加)
- treeview右键单击一个node不会选中这个node,如何使得可以选中?
- 如何检测一个目录下面是否有文件产生,修改?
using System.Diagnostics;
using System.Threading;
public class CpuLoadInfo
{ // auxiliary print methods
private static void Say ( string txt )
{
Console.WriteLine(txt);
} // auxiliary print methods
private static void Say()
{
Say("");
} // The main method. Command line arguments are ignored.
[STAThread]
public static void Main()
{
Say("$Id: CpuLoadInfo.cs,v 1.2 2002/08/17 17:45:48 rz65 Exp $");
Say(); Say("Attempt to create a PerformanceCounter instance:");
Say("Category name = " + CategoryName);
Say("Counter name = " + CounterName);
Say("Instance name = " + InstanceName);
PerformanceCounter pc
= new PerformanceCounter(CategoryName,CounterName,InstanceName);
Say("Performance counter was created.");
Say("Property CounterType: " + pc.CounterType);
Say(); Say("Property CounterHelp: " + pc.CounterHelp);
Say();
Say("Entering measurement loop."); while (true)
{
Thread.Sleep(1000); // wait for 1 second
float cpuLoad = pc.Nextvalue();
Say("CPU load = " + cpuLoad + " %.");
}
} // constants used to select the performance counter.
private const string CategoryName = "Processor";
private const string CounterName = "% Processor Time";
private const string InstanceName = "_Total";
}这是在我计算机上的计算结果:
Entering measurement loop.
CPU load = 0 %.
CPU load = 1.941746 %.
CPU load = 4.854369 %.
CPU load = 10 %.
CPU load = 0 %.
CPU load = 2.999997 %.
CPU load = 0.9900987 %.
CPU load = 0 %.