简体   繁体   中英

how to estimate a process time through C#

how can I calculate the processing time, for example for copying a file from 1 folder to another? opening a web browser or calculator. the command is given to c# by a batch file the c#first read this file execute it and tell me the time span of each process.

A stopwatch is best for calculating elapsed time

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);

If it's only the processing time AFTER the process, so you need just to use a StopWatch . Create and start a StopWatch just after the process beggining and stop the watch when the process end, then you can get the elapsed time from the StopWatch.

But if you want to predict the time that a process is gonna take, then you can just estimate from previous process times if it's a more fixed-time process or elaborate some relationship about the parameters and the time consuming of the process.

Maybe you can use this link to help you out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM