System.Diagnostics 命名空间 ​

1)提供允许你与系统进程、事件日志和性能计数器进行交互的类(EventLog​、Process​、PerformanceCounter);

2)提供一些可用于调试并跟踪代码执行的类(Trace​、Debug​、Stopwatch)。



1. 运行时间精准测量 System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); // // 监控用时的中间代码... // sw.Stop(); long len = sw.ElapsedMilliseconds;


//2.设置断言,打印输出 //如:重载窗口函数 protected override void OnResize(EventArgs e) {     base.OnResize(e);     System.Diagnostics.Debug.Assert(this.Width > 200, "width should be larger than 200.");     System.Diagnostics.Debug.WriteLine(this.Size.ToString());  }