private void spotterWork()
{
int threadSleepTime = ((int) spotterInterval.Milliseconds / 10) + 1;
DateTime nextRunTime = DateTime.Now;
Console.WriteLine("Invoking spotter every " + spotterInterval.Milliseconds + "ms, pausing " + threadSleepTime + "ms between invocations");
while (runSpotterThread)
{
DateTime now = DateTime.Now;
if (now > nextRunTime && spotter != null && gameDataReader.hasNewSpotterData())
{
currentSpotterState = gameDataReader.ReadGameData(true);
if (lastSpotterState != null && currentSpotterState != null)
{
try
{
spotter.trigger(lastSpotterState, currentSpotterState);
}
catch (Exception e)
{
Console.WriteLine("Spotter failed: " + e.StackTrace);
}
}
lastSpotterState = currentSpotterState;
nextRunTime = DateTime.Now.Add(spotterInterval);
}
Thread.Sleep(threadSleepTime);
}
spotterIsRunning = false;
}