首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

c# 里面如何实时的真测一个程序的内存消耗

2012-02-23 
c# 里面怎么实时的真测一个程序的内存消耗如题,最好能给些代码。[解决办法]调用性能计数器C# codeclass Pro

c# 里面怎么实时的真测一个程序的内存消耗
如题,最好能给些代码。

[解决办法]
调用性能计数器

C# code
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");        }    } 

热点排行