/// <summary>
/// This method is responsible for monitoring system resource and user activity with the computer
/// And periodically changes the shared variable 'crawlerState'
/// </summary>
public void Scheduler()
{
PerformanceCounter pc = new PerformanceCounter("Processor", "% Idle Time", "_Total", true);
LASTINPUTINFO info = new LASTINPUTINFO();
info.cbSize = Marshal.SizeOf(typeof(LASTINPUTINFO));
while (GlobalData.RunScheduler)
{
if (GetLastInputInfo(ref info))
{
if ((Environment.TickCount - info.dwTime) / 1000 > 5 && (int)pc.NextValue() > 40)
{
crawlerState = CrawlerState.Run;
}
else
{
crawlerState = CrawlerState.Stop;
if ((Environment.TickCount - info.dwTime) / 1000 <= 5)
GlobalData.lIndexingStatus.Text = string.Format("Indexing is paused and will be resumed in {0} sec of computer inactivity [ CPU Idle : {1:F2}% ]", 5 - (Environment.TickCount - info.dwTime) / 1000, pc.NextValue());
}
}
Thread.Sleep(1000);
}
pc.Close();
}