Dectect program startup times in C#

pcnerd37

Senior member
Sep 20, 2004
944
0
71
Im researching an application that Im designing and I was wondering if it is possible with C# to detect the startup times of other programs such as MSN Messenger, Anti Virus, Firewall, and other applications. Im working on a program that makes windows bootup more efficient, and im wondering if its possible to detect how long it takes a program to completely launch. If it is, how would I go about doing so? Thanks for any help you guys can give me!
 

BradAtWork

Senior member
Sep 5, 2005
320
0
0
System.Diagnostics.Process.StartTime

So

foreach(System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
{
Console.WriteLine(p.StartTime);
}

I do VB.Net not C#, but that should work.
 

Tencntraze

Senior member
Aug 7, 2006
570
0
0
The hard part about this is when would you know when a program is "completely launched"? There's not going to be any specific event or callback that I can think of that will say that the program's loading/initialization has completed. I suppose you could use some arbitrary CPU cycle monitoring to take an educated guess at when it might be completed.
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
Originally posted by: BradAtWork
System.Diagnostics.Process.StartTime

So

foreach(System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
{
Console.WriteLine(p.StartTime);
}

I do VB.Net not C#, but that should work.

This really wont do what the OP is asking - it just returns the time the process was started, not how long they took to start. Although, maybe it could help him a bit.

I agree with Tencntraze, there is not specific event or callback to know when something is done loading. The only thing i can think of is using FindWindow to see when the programs main window opens (assuming it has one), and compare that to the process start time. But this wont work for many/most program - it's hit or miss.

There are alot of other factors, like what is included in the startup time - for example, i have my MSN to auto login, is the startup done AFTER it logs in, or before? For antivirus, it updates its definitiions everyday - is it before it updates or after? There are a lot of factors to consider. I wish i had a better answer for the OP, but i' dont.
 

pcnerd37

Senior member
Sep 20, 2004
944
0
71
yea, that is what I think the biggest technical issue would be. What im trying to do is analyze the windows booting to the desktop to find out when a program starts to launch and when it has completely launched. My ultimate goal is to be able to create a delay between programs starting so not everything is trying to get pulled from the hard drive at once, but I would like to be able to figure out how long it takes a program to load so that I can best analyze the results and set the delay to make the best use of system resources.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Originally posted by: pcnerd37
yea, that is what I think the biggest technical issue would be. What im trying to do is analyze the windows booting to the desktop to find out when a program starts to launch and when it has completely launched. My ultimate goal is to be able to create a delay between programs starting so not everything is trying to get pulled from the hard drive at once, but I would like to be able to figure out how long it takes a program to load so that I can best analyze the results and set the delay to make the best use of system resources.

Interesting. Why do you think that would improve on Windows' native startup process and file I/O? Windows doesn't try to launch all the startup programs at once. It reads in the things like the Run and RunOnce keys, the shortcuts in the Startup folder, and enumerations of services to be launched, and then processes these lists launching each program in turn. The process of loading each program issues file i/o requests, as does the program's initialization once loaded. I am not sure whether XP waits for the completion of each process, or not, and that behavior may differ for services vs. Run key items vs. startup folder items, but in any event I doubt your strategy would greatly improve on its ability to manage the operations that are interleaved. My guess is it would just extend the boot process.
 

pcnerd37

Senior member
Sep 20, 2004
944
0
71
Well, it was just an idea that was given to me by a MS employee that he believed it would help the bootup process. If nothing else, just create a delay for non essential programs that launch at bootup like winamp, nero, and others so that windows would be more responsive and usable sooner.