System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
watch.Start(); //開始監(jiān)視代碼運行時間
//需要測試的代碼
watch.Stop(); //停止監(jiān)視
TimeSpan timespan = watch.Elapsed; //獲取當(dāng)前實例測量得出的總時間
System.Diagnostics.Debug.WriteLine("打開窗口代碼執(zhí)行時間:{0}(毫秒)", timespan.TotalMilliseconds); //總毫秒數(shù)