using System.Diagnostics;

private Stopwatch stw = new Stopwatch();
stw.Start();
stw.Stop();
MessageBox.Show("程序共运行时间:" + stw.Elapsed.Seconds.ToString() + "秒");
05-19 14:56