private void StartUpdateCycle() { Globals.WriteToDebugFile("TaskMonitor: Starting Update Cycle"); while (!_shutdown) { int msToWait = 0; _positionTools.Init(); // start location stuff (if it is no already started) // Lock - Make sure there's nothing changing the task list lock (_taskMonitorList) { msToWait = ProcessTasks(); } if (msToWait > 1800000) // 1800000ms = 30min { // we will not need location stuff for a long time, so // let's turn it off to save some battery _positionTools.Shutdown(); // let's wake it some minutes before any task needs to be // processed to give GPS some time to initialize msToWait -= 300000; // 300000ms = 5min } SleepingPrincess(msToWait); if (_errorCount > 5) { _shutdown = true; } } }