c# 里面怎么实时的真测一个程序的内存消耗
如题,最好能给些代码。
[解决办法]
调用性能计数器
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"); } }