//程序开始的时间
DateTime xjDTStart = DateTime.Now;
#region
...
#endregion
//中间代码运行之后的时间
DateTime xjDTEnd = System.DateTime.Now;
TimeSpan xjTimeSpan = xjDTEnd.Subtract(xjDTStart);
//格式为 小时:分钟:秒
string xjTime = xjTimeSpan.ToString("c").Substring(0, 8);
MessageBox.Show("所用时间=" + xjTime);
