请问用C#如何得到当前cpu的使用率以及如何获得本进程的内存使用大小? GC.GetTotalMemory(False)获得系统内存的使用情况 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=6977HLMY-ELPN-4KIR-BI89-7YS2LNENT5HR这里有vb的,很容易翻成cs的 System.Diagnostics.Process类下有如下方法:PagedMemorySize 获取分页的内存大小。 PagedSystemMemorySize 获取分页的系统内存大小。 PeakPagedMemorySize 获取峰值分页内存大小。 PeakVirtualMemorySize 获取峰值虚拟内存大小。 VirtualMemorySize 获取进程的虚拟内存大小。 WorkingSet 获取关联进程的物理内存使用情况。 .....Process 组件是很有用的工具。使用 Process 组件,可以获取当前运行的进程的列表,或者启动新的进程。Process 组件用于访问系统进程。初始化 Process 组件后,可使用该组件来获取有关当前运行的进程的信息。此类信息包括线程集、加载的模块(.dll 和 .exe 文件)和性能信息(如进程当前使用的内存量)。 那请问当前cpu的使用率 用什么函数可以查到? 这个是孟老大的取得cpu的利用率:using System;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";} C#项目中数据库生成的mdf文件放在什么位置才能与C#中的控件进行绑定? 刚学C#,一段修改简单代码 .net 怎样对图片操作 简单问题,来者有分(关于设计模式) 我要用OWC从数据库里读数据到OFFICE的各种表里,要用OWC,请教有学习OWC的资料吗? 请大家指点:我是初学者,希望大家介绍一些书籍,给予建议!急!! 如何实现数字位数的压缩,如32位变成16位 一个关于qq的问题 请教一个ACCESS数据绑定问题? 问一个古董级的问题 C#winform程序如何判断远程是否有指定的文件存在? ASP.net Webmtrix 1.0教程哪里有?
这里有vb的,很容易翻成cs的
PagedMemorySize 获取分页的内存大小。
PagedSystemMemorySize 获取分页的系统内存大小。
PeakPagedMemorySize 获取峰值分页内存大小。
PeakVirtualMemorySize 获取峰值虚拟内存大小。
VirtualMemorySize 获取进程的虚拟内存大小。
WorkingSet 获取关联进程的物理内存使用情况。
.....
Process 组件是很有用的工具。使用 Process 组件,可以获取当前运行的进程的列表,或者启动新的进程。Process 组件用于访问系统进程。初始化 Process 组件后,可使用该组件来获取有关当前运行的进程的信息。此类信息包括线程集、加载的模块(.dll 和 .exe 文件)和性能信息(如进程当前使用的内存量)。
取得cpu的利用率:
using System;
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";
}