System.Diagnostics.Stopwatch stopwatch = new Stopwatch();
stopwatch.Start(); // 開始監視代碼運行時間
//需要監測的代碼
stopwatch.Stop(); // 停止監視
TimeSpan timespan = stopwatch.Elapsed; // 獲取當前實例測量得出的總時間
string hours = timespan.TotalHours.ToString("#0.00000000 "); // 總小時
string minutes = timespan.TotalMinutes.ToString("#0.00000000 "); // 總分鍾
string seconds = timespan.TotalSeconds.ToString("#0.00000000 "); // 總秒數
string milliseconds = timespan.TotalMilliseconds.ToString("#0.00000000 "); // 總毫秒數
