Why is my application startup time slower when I use Process.Start ()?

I am trying to profile the startup time of my application, so I wrote a small C # program that will launch my application using the Process.Start () method, and the time it used the stopwatch.

When I try to start the application on my own (just by clicking on it), it probably takes 2-3 seconds. When I try to run the application using my test program, it takes 8-10 seconds. Start-up time is constantly different from this value.

Any idea why using Process.Start to run the executable affected the launch time so much?

+6
c # app-startup
source share
3 answers

Thank you for your help. I have an answer and it is not related to Process.Start.

After starting the process, I expected a specific window handle to appear to find out that the application really appeared. The loop was too tight. I entered a 200 ms sleep in a while loop, and the start time was normal again.

+1
source share

Your hint should be that Process.Start() is in the System.Diagnostics namespace. When you start the process this way, you attach a bunch of monitors / inspectors to it. This definitely adds overhead.

You may want to immediately call Dispose() on the Process object after it starts (to avoid monitoring the process unnecessarily long), but you cannot completely avoid the overhead involved.

0
source share

Simply put, you are actually starting two processes, not just one. That is why it takes longer.

When you double-click on your application, you download only one application and all its DLLs.

When you run the diagnostic application, you first download the first application with its .NET assemblies, which should be JIT'd (only at compile time: it's not free). Only after that everything will be completed, then the OTHER application will start working. If your target application is also a .NET application, then the whole cycle repeats.

0
source share

All Articles