I'm trying to find out when a process has stopped doing his work. I've been trying it with this code but it doesn't notice that the program is still running and processing a file. Probably because it's still doing things that take less then one microsecond:
TimeSpan startTime = m_Process.TotalProcessorTime;
int idleCycles = 0;
int iMax = Math.Max(iMinNoActivityTime/100, 5);
while (idleCycles < iMax)
{
Sleep(100);
TimeSpan curTime = m_Process.TotalProcessorTime;
int delta = curTime.Subtract(startTime).Milliseconds;
if (delta != 0)
{
idleCycles = 0;
}
else
{
idleCycles++;
}
startTime = curTime;
}
It's called for 3000 seconds: 30 consecutive time-blocks of 100 miliseconds without processor activity.
Is there any way to do this so it doesn't see it as idling when it's still running? The process reads the file, deletes it and then processes it so it can't monitor the directory.