Detect idle computer

Posted on 2006-05-15
Last Modified: 2008-01-09
How would I go about detecting if the computer has gone idle? maybe screen saver or monitor power saver ?
Question by:addicktz
    LVL 12

    Accepted Solution

    Use the OnIdle ( ok.. C# Application.Idle  ) event

    from < >
    The best way to enable and disable buttons, menu items and toolbar buttons
    Write an OnIdle method and put your GUI enable/disable code there. The OnIdle method is called every time your application's message queue becomes empty.

    Hook in the OnIdle method in a Form's constructor by instantiating an EventHandler and adding that hander to the Appliction object's Idle property. Update the form's GUI in the OnIdle method. Finally, be sure to remove the EventHandler from the Application object's Idle property when the Form is about to close.

    private EventHandler idleEventHandler;

    public SettingsForm(InitialTabPage initialTabPage)


          idleEventHandler = new System.EventHandler(OnIdle);
          Application.Idle += idleEventHandler;


    private void OnIdle(object sender, EventArgs e)
          // Update form's UI when program is idle.

          deleteButton.Enabled = assemblyListBox.SelectedIndex != -1;

    private void SettingsForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)

          Application.Idle -= idleEventHandler;
    LVL 12

    Assisted Solution


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now