Detect When Application Is Idle

I am looking for the best way to detect when a specific application is idle. In Task Manager there is the CPU column that indicates if a process is 0 or some other value. I want to know when a specific process is at 0 and remains in that state. I have a particular app that is always running in the background and should be consuming some CPU time all the time. For the most part it does, but occasionally it goes idle and I need to know when it does.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


Have you ever tried to add and Handler on the Application.Idle event ?
Hello abnc,

Short answer:

As CalVerret mentioned, the most likely solution will be to handle the Application.Idle event. In your applications New() sub procedure, add the following code:

Public Sub New()
      AddHandler Application.Idle, AddressOf MyApplicationName_Idle
End Sub

Then create a method to handle this event:

Private Sub MyApplicationName_Idle(ByVal sender As Object, ByVal e As EventArgs)
      ' Perform appropriate tasks while the application is idle
End Sub


If your application is a Windows Forms application you can subscribe to the Application.Idle event. This can be done in the New() sub of the class. When the application finishes processing all of its tasks, it will automatically enter an idle state.

Reference to this event on MSDN2

There are other ways to manage processes on your computer as well. The following reference explains more about this:

Description of how to use Events and Delegates


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
abncAuthor Commented:
My console app is endeavoring to check the idle state of another app. That app is not one I have written so I cannot change the underlying code. I need to know when that app's process is idle using no CPU time.
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Hi again,

Is there any way that you could monitor this app with a PerformanceCounter object ?
abncAuthor Commented:
I have looked at the system diagnostics but don't see yet anyway to see what the current status of a specific process is regarding CPU time. I see I can get the TotalProcessorTime, but I want to know if that process is using any CPU time at a given moment. Obviously, Windows Task Manager is getting that data and showing it on the Processes Tab.

By way of information, the app I am checking shows up in the list of Applications in Windows Task Manager, but on random occasions it disappears from that list but is still listed among the processes. However, it is showing 00 CPU time and I need to know when it is in that state. Perhaps there is some way of checking for it among the list of applications rather than processes, although I would prefer to be able to check it's process current status.
Hello, abnc

An application is always associated with a process. In this case, I think you want to monitor the process and take action based on its state.

In order to continually monitor the processes on your machine (similar to the task manager) you may need to create a Windows service. A Windows service is often used for long-running processes (such as continually monitoring processes) that don't interfere with other applications and users.

Look at to see how you can create and set up a Windows service application.
abncAuthor Commented:
Several of these things I already had tried and is not the exact solution I was seeking. I finally came up with a method using part of what I had already tried and some of what was suggested.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.