Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application that I need to start on User logon (with a Registry Run key) [Thanks Dave Kreskowiak].

My question is this : on startup, the application performs a number of operations that may be costly, and on slow computers the added overhead will surely not be appreciated. On the bright side I can delay the application startup to a later time. The question is, what do you think would be a good approach to reduce my application overhead from system startup.

Idea #1 :
System.Threading.Thread.Sleep(10000); // How much do you really wait?

Yes that could get the job done I guess, but I think it's a rather dirty solution, and besides hardcoding a number of seconds (such as 10) isn't really scalable to other systems that may be faster / slower.


Idea #2 :
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Low;

This could maybe work, but I'm still hoping there are better solutions that can delay the application startup, just like you could select Delayed Startup with windows services.

Thanks :)
Posted
Updated 15-Oct-13 2:31am
v2

1 solution

First of all, running anything out of the Registry Run key is NOT "at Windows startup". What you're referring to is "at user logon".

Windows startup would be a service application.

Idea #3. User the performance counters to poll for CPU and Hard Drive usage every once in a while. When they are both below a certain threshold, kick off your code.
 
Share this answer
 
Comments
Trapper-Hell 15-Oct-13 8:28am    
You are correct. I meant to say user logon. My bad.

Can you provide any sample code for the CPU polling? And will the polling itself be expensive?
Dave Kreskowiak 15-Oct-13 10:02am    
I don't have to. There are tons of examples all over the web. Just Google for "C# performance counter CPU usage".
Trapper-Hell 15-Oct-13 10:08am    
I know I could have searched, but I asked you to form a complete solution. That still didn't answer whether you consider that CPU-expensive or efficient. I have however taken the liberty to test it myself (with code I had found through a Google-search in the mean time) and yes it does appear to work well, even though I believe I'll have to take a couple of readings before determining whether CPU usage has really been reduced.

Nonetheless, I'm going to accept yourself for taking the time to reply, and for suggesting a relatively good idea.
Dave Kreskowiak 15-Oct-13 10:16am    
If you want a complete solution, YOU have to code it. I just gave you the push in the direction you needed to go. The "complete" solution is the one where you teach yourself something in the process. Where you exercise your skills to do research. Without that skill you will not last very long writing code.

Do you want to tell me how "incomplete" my solution was again?? :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900