如何通过C#估算处理时间

时间:2014-11-01 15:08:53

标签: c#

如何计算处理时间,例如将文件从1个文件夹复制到另一个文件夹? 打开网络浏览器或计算器。该命令由批处理文件提供给c#,c#首先读取该文件执行它并告诉我每个进程的时间跨度。

2 个答案:

答案 0 :(得分:1)

秒表最适合计算经过时间

stopwatch sw = new stopwatch;
sw.Start();
// do something here that you want to measure
sw.Stop();

// Get the elapsed time as a TimeSpan
TimeSpan ts = sw.Elapsed;

// Format and display the TimeSpan
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("That took: {0}", elapsedTime);

答案 1 :(得分:0)

如果它只是处理后的处理时间,那么您只需要使用StopWatch。在流程开始后立即创建并启动StopWatch,并在流程结束时停止监视,然后您可以从StopWatch获取已用时间。

但是如果你想预测一个过程将要花费的时间,那么你可以从之前的过程时间估计它是否是一个更固定的时间过程或者详细说明一些关于参数和时间的关系。这个过程。

也许您可以使用此link来帮助您。