System.Diagnostics.Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); //执行代码+++ var d = stopwatch.Elapsed.Seconds; stopwatch.Stop();