一、新建一个控制台程序项目Test.exe
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace CodeRunTimeTest
{
public class Program
{
static void Main(string[] args)
{
if (args.Length > )
{
Console.WriteLine("代码运行时间为:" + args[]);
}
else
{
Console.WriteLine("没有输入时间!!!");
}
Console.ReadLine();
}
}
}
二、在工作项目代码中添加
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start(); /*测试代码*/ sw.Stop();
System.Diagnostics.Process.Start(Application.StartupPath + "\\test.exe ", sw.Elapsed.ToString());
三、结果显示(不影响工作项目的运行)