Reputation: 36111
Log("Starting to compile...\n");
Process p = new Process();
p.StartInfo.FileName = CompilationCommand;
p.StartInfo.Arguments = SourceFileName;
p.Start();
Log("Compiling finished in " + (p.StartTime - p.ExitTime).Seconds + " seconds\n");
This code doesn't work. How can I find out how much time was spent on compiling a C++ source file with g++ compiler?
Upvotes: 0
Views: 461
Reputation: 17909
Have a look at implementing the process.Exited event.
This MSDN article has a good sample:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exittime.aspx
Upvotes: 1
Reputation: 17973
You can use the WaitForExit function in process to wait for the process to exit along with the Stopwatch class to measure the time it took. This would result in you having a thread waiting for the process to exit.
Stopwatch watch = Stopwatch.StartNew();
// start process as before
process.WaitForExit();
TimeSpan ts = watch.Elapsed;
Upvotes: 2
Reputation: 146930
Processes run asynchronously to other processes but you don't wait for it to finish. By the time your Log call returns, the process could still be running away.
Upvotes: 1