Getting idle time of process.

  • Thread starter Thread starter archana
  • Start date Start date
A

archana

Hi all,

I want to get idle time of process. Means time in which process is
sitting idle.

Can i do this in c#.

Because what i want is those process which are not running since say
last 10 mins kill those processes.

please help me asap.

thanks in advance.
 
Killing random processes is a very, very bad idea. Also, getting the
"not running since" time is tricky, since many processes will be
semi-idle - i.e. the OS will offer them time and they will simply put
themselves back to sleep.

What are you trying to achieve here?

Marc
 
For a more direct answer, you can periodically query
Process.GetProcesses(), and (for each, matching presumably on .Id),
compare the .TotalProcessorTime with what it was last time you
checked, and call .Kill() for any that you don't like...

But again - don't go killing at random; many essential system
processes would (using the above) show as idle. I would say limit
yourself to apps that you know about, but even that is risky; killing
a process is very brutal. You could try CloseMainWindow() first, but
to be honest I don't like the sound of this entire concept...
Processes should shut themselves down cleanly when they are happy
to...

Marc
 
Hello archana,

just to add to Mark's post, you can use Application.Idle for Winforms projecs

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


a> Hi all,
a>
a> I want to get idle time of process. Means time in which process is
a> sitting idle.
a>
a> Can i do this in c#.
a>
a> Because what i want is those process which are not running since say
a> last 10 mins kill those processes.
a>
a> please help me asap.
a>
a> thanks in advance.
a>
 
you can use Application.Idle for Winforms projecs

Application.Idle is for the /current/ process, but given the talk of
processes, I assume that we are talking out-of-process, so this
probably won't do quite what the OP requires.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top