Question

I am writing an application that runs on Windows logon but I want it to wait until the desktop is fully functional/loaded before it actually starts doing anything. Is there any way of working out when Windows has completely finished loading the desktop?

Was it helpful?

Solution

On vista you could use a service in Automatic (Delayed) mode, this would start before log on if no one logged on fast enough though but if you wished to avoid running until much of the system had become ready this would work. If you are heavily user centric in your desire to wait till they are ready then you will likely have to use user centric triggers.

Several metrics exist which would give you a good idea of whether the user considered the session ready for use:

  • CPU load of processes associated with the System account were no longer taking a significant proportion of the CPU time.
  • The user has begun interacting with the UI (so significant mouse movement or keyboard activity)
  • network connectivity is established

Since these are heuristics you should have some time based constraints for the minimum and maximum possible wait in case they misfire.

OTHER TIPS

Very old question but I needed the same. The following code seems to work:

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        // wait until desktop ready

        IntPtr lHwnd = IntPtr.Zero;
        do
        {
            lHwnd = FindWindow("Shell_TrayWnd", null);
            Thread.Sleep(100);
        } while (lHwnd == IntPtr.Zero);

I assume you're primarily referring to interactive UI-based apps and not system services.

There's no way to know when the other applications have finished loading, since the definition of "finished" isn't clear cut. However you can control the startup order of applications using a third party utility such as http://www.chameleon-managers.com/windows-startup-manager/startup-delayer.php.

I'm curious to understand what effect you're trying to achieve by having your application run only after the other desktop applications have completed loading. Knowing this might help to suggest alternative answers.

Regards

In the load of your application couldn't you enter into a timer loop and wait until all your prerequisite processes are loaded by monitering the process list. Once conditions are satisfied then you could continue with initializing your application.

Process[] apps  =   Process.GetProcesses();

Just install your application into the startup folder. Also look at the wikipedia page on startup. To install a C# application in the startup folder read this.

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