Is it possible to find the time taken to run the project file?  
Author Message
Prabu.





PostPosted: Visual C# General, Is it possible to find the time taken to run the project file? Top

How can I find an exact timing taken for run the project files I am using devenv.exe to run the application. I need to hold the till the project gets run. Here is the code I had tried. Please help.

 

foreach ( FileInfo file in d.GetFiles ( “*.csproj” ) )

{

string Arg = string.Format ( "\"{0}\" /run /out \"{1}\"" , file.FullName, d.FullName + "\devenv.log" );

Process p = new Process();

      p.StartInfo = new

      p.StartInfo.Arguments = Arg;

      p.StartInfo.CreateNoWindow = true;

      p.StartInfo.ErrorDialog = true;     

      p.StartInfo.RedirectStandardOutput = true;

      p.StartInfo.UseShellExecute = false;

      p.StartInfo.WorkingDirectory = d.FullName;

      p.Start();  

      Console.WriteLine ( p.StandardOutput.ReadLine() );

      Thread.Sleep ( new TimeSpan( 0, 0, 10   ) ); //No need to give the manual delay time. I need to give an exact time taken to run the samples.

}

 

Thanks in Advance.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />




Visual C#16  
 
 
Paul Louth





PostPosted: Visual C# General, Is it possible to find the time taken to run the project file? Top

Rather than putting the thread to sleep, do this:

p.WaitForExit();


 
 
Prabu.





PostPosted: Visual C# General, Is it possible to find the time taken to run the project file? Top

This will wait until I quit from devEnv application. Just I need to know the time taken to run the given sample project by devEnv application. Then only I will give the wait time for the next samples project taken to execute.

 
 
Paul Louth





PostPosted: Visual C# General, Is it possible to find the time taken to run the project file? Top

Ok, well run it once and do this:

DateTime start = DateTime.Now;
p.WaitForExit();
DateTime finish = DateTime.Now;
TimeSpan timeTaken = finish - start;

Then use the value in the timeTaken to work set the Wait period.


 
 
TomPearson





PostPosted: Visual C# General, Is it possible to find the time taken to run the project file? Top

From Paul's post I believe the application won't exit unless manually exited from. When run from the command line wth the /run switch the IDE stays active, see http://msdn2.microsoft.com/en-us/library/cc22sde0(VS.80).aspx

Also couple of points from you current code.
Firstly if you have loads of project files in the directory the time taken to run them will get longer and longer as resources are used up on your system by the muliple copies of the IDE you will be creating.
Secondly the time recorded will always depend on what needs recompiling.

I think you need to be more clear about what you are trying to record. From your code it looks like you are trying to find out how long it takes to start the IDE, compile the executable, and run it, which seems an odd thing to do. Is this really your aim

 
 
Prabu.





PostPosted: Visual C# General, Is it possible to find the time taken to run the project file? Top

Thanks for the explanation. Yes, you are correct. Actually I am trying to do, check whether the sample projects that are taken from the given path and it get running successfully or not. It need time delay between two processes.

While I tried to run the sample by using devEnv.exe [using this option http://msdn2.microsoft.com/en-us/library/cc22sde0(VS.80).aspx] it hold remain the process until I manually close the process. Instead I will kill the current process after the samples gets ran. So I need to kill the process once the sample gets success or failure. I need to give the exact time delay for the process.

Please let me know If any other possibilities available for this scenario. Thanks in advance.