Beispiel #1
0
        private void Scheduler()
        {
            LoadSchedule();

            while (true)
            {
                try
                {
                    Program.Log("Medlem3060Service Scheduler() loop start");
                    dbJobQDataContext dbJobQ = Program.dbJobQDataContextFactory();
                    int?   id      = null;
                    string jobname = null;
                    if (dbJobQ.jobqueuenext(ref id, ref jobname) == 0)
                    {
                        if (Enum.IsDefined(typeof(enumTask), jobname))
                        {
                            Task <int> task = new Task <int>(() => JobWorker(jobname));
                            task.Start();
                            int resultat = task.Result;
                        }

                        dbJobQ.jobqueuecomplete((int)id);
                    }
                    else
                    {
                        if (_waitStopHandle.WaitOne(2 * 60000))
                        {
                            break;
                        }
                    }
                }
                catch (Exception e)
                {
                    Program.Log(string.Format("Medlem3060Service Scheduler() loop failed with message: {0}", e.Message));
                    if (_waitStopHandle.WaitOne(5 * 60000))
                    {
                        break;
                    }
                }
            }
        }
 private void LoadSchedule(int days = 2)
 {
     try
     {
         dbJobQDataContext dbJobQ = Program.dbJobQDataContextFactory();
         var Schedules            = from s in dbJobQ.tblSchedules orderby s.start select s;
         foreach (var s in Schedules)
         {
             if (Enum.IsDefined(typeof(enumTask), s.jobname))
             {
                 var occurrence = CrontabSchedule.Parse(s.schedule).GetNextOccurrences(DateTime.UtcNow, DateTime.UtcNow.AddDays(days)).GetEnumerator();
                 while (occurrence.MoveNext())
                 {
                     dbJobQ.jobqueueadd(occurrence.Current, s.jobname, s.id, false);
                 }
             }
         }
     }
     catch (Exception e)
     {
         Program.Log(string.Format("Medlem3060Service LoadSchedule() failed with message: {0}", e.Message));
     }
 }