C# 如何计算流程的执行时间?

C# 如何计算流程的执行时间?,c#,C#,执行一个流程需要多少时间。我在下面创建了一些流程,必须找到这些流程的执行时间 string path = @"C:\Users\Abbas\Desktop\Processes\p"+a+".txt"; begin = Process.GetCurrentProcess().TotalProcessorTime; TextWriter tw = new StreamWriter(path, true); tw.WriteLine("T

执行一个流程需要多少时间。我在下面创建了一些流程,必须找到这些流程的执行时间

        string path = @"C:\Users\Abbas\Desktop\Processes\p"+a+".txt";
        begin = Process.GetCurrentProcess().TotalProcessorTime;
        TextWriter tw = new StreamWriter(path, true);
        tw.WriteLine("The next line!");
        tw.Close();
        end = Process.GetCurrentProcess().TotalProcessorTime;
        MessageBox.Show("Process " + a + " created.");
        a++;

像这样使用
秒表
类:

var watch = System.Diagnostics.Stopwatch.StartNew();

TextWriter tw = new StreamWriter(path, true);
tw.WriteLine("The next line!");
tw.Close();

watch.Stop();
var elapsedMs = watch.ElapsedMilliseconds;

@SheikhAbbas:如果它解决了你的问题,请投票并标记为答案。