Question

I have an GUI application that takes a while to load all its plugins, before it is ready to be used by the user.

I want to write a C# program that would measure the time taken for this application to start up. I thought the Process.WaitForInputIdle() method would do the trick, but it doesn't. It exits as soon as the process is started.

What I have now is this:

DateTime startTime = DateTime.Now;

Process myAppUnderTest = Process.Start("C:\\Program Files\\My App\app_under_test.ext");

myAppUnderTest.WaitForInputIdle();   //Wait until the application is idle.

DateTime endTime = DateTime.Now;

int elapsedTimeInSecs = endTime.Subtract(startTime).Seconds;

Console.WriteLine("Start up time (sec): {0}", elapsedTimeInSecs);

How can I get the start up time that I intend?

Was it helpful?

Solution

I say it's very difficult.

How do you classify an application loaded and ready? If there is a way (which I don't think so) then it would be easy.

But if the app you are loading signals you in certain way (IPC/files/network), then you can capture that signal and say the app is loaded. In that case, you can use a timer/stopwatch/performance counter.

If you can modify the to be timed app, then you can achieve in various ways. If its external to you, I doubt there is any easy way.

OTHER TIPS

Process.WaitForInputIdle() respones to the main window. Once that process starts up it will move on. Is there a message on the main the main window you can look at that indicates the app is in a ready state? If so you can try putting or app in a loop unitl that is present or so much time has passed. As has been noted you will probably also want to look at the Stopwatch class for your timing.

Just a couple of other thoughts as you are doing this. Make sure that this process is the only one running. You can sometimes get some conflicts otherwise. You may need to play arround with figuring out what the trigger is to tell you when the app is fully loaded.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top