Can can one determine % CPU in use by a spawned process

  • Thread starter Thread starter Jason Kendall
  • Start date Start date
J

Jason Kendall

I have a task to create an app to rebuild indexes for an ancient
program. The program has an API, but leveraging it requires the app's
UI to launch. OK, that's fine, I can just ignore it... at least it
unloads when I tell it to. The problem is that occasionally there is
one thing or another wrong with one of the files needing reindexed and
the app pops up a dialog box for the user to respond to. I've never
heard of this kind of silliness with an API. If one of these dialogs
pops up, it's acceptable for me to email an operator about the
particular file and let them manually resolve the issue.

What I need to do is be able to look at % CPU for the process so I can
guess whether the app is waiting for someone to click "OK" or if it's
still working. There are approximately 79,000 files to be reindexed
and some take as long as 15 minutes to complete, so we really need to
be able to respond to a "hung" reindex and kill it so we can move on
to the next.

Thanks!
 
use WMI ( System.Management )
you can use SQL like WHERE clause to search by processID

Compare obtained usermodetime with SystemIdlePrcess time and you will get
what you need.
SystemIdleProcess id is 0.

using System;
using System.Management;

class Sample
{
public static void Main()
{
ManagementClass c = new ManagementClass("Win32_Process");

foreach (ManagementObject o in c.GetInstances())
{
Console.WriteLine("Process Load= {0}", o["UserModeTime"]);
}
}
}
 
Back
Top