日期:2014-05-18 浏览次数:20930 次
class Program { //实例化一个性能计数器,统计可用内存数(消耗的话就用总内存数去减去可用数) private static System.Diagnostics.PerformanceCounter perfCounter= new System.Diagnostics.PerformanceCounter("Memory", "Available KBytes"); static void Main(string[] args) { System.Threading.Timer timer = new System.Threading.Timer(new System.Threading.TimerCallback(counter),null,0,1000); Console.ReadLine(); } private static void counter(object state) { float count = perfCounter.NextValue(); Console.WriteLine(count + "KBytes"); } }