Пример #1
0
        private int ProcessTasks()
        {
            int         msToNext      = 86400000; //24h * 60m * 60s * 1000 <- the max wait time is 24h
            Time        now           = new Time(DateTime.Now);
            int         msFromLastUpd = TimeFuncs.GetMsFromTo(_lastUpdate, now);
            Coordinates currentPos    = _positionTools.GetCurrentPosition(_updateRate);

            foreach (TasksMonitorTask tmt in _taskMonitorList)
            {
                tmt.msToStart -= msFromLastUpd;

                if (tmt.msToStart <= 0)
                {
                    tmt.msToStart = GetMsToTask(now, tmt.task);

                    // re-check
                    if (tmt.msToStart <= 0)
                    {
                        if (currentPos.IsValid())
                        {
                            if (ProcessTask(tmt.task, currentPos))
                            {
                                tmt.msToStart = TimeFuncs.GetMsFromTo(now, tmt.task.MonitorStartTime);
                            }
                        }
                    }
                }

                if (msToNext > tmt.msToStart.Value)
                {
                    msToNext = tmt.msToStart.Value;
                }
            }

            if (msToNext < _updateRate)
            {
                msToNext = _updateRate;
            }

            _lastUpdate = now;
            return(msToNext);
        }