Example #1
0
 /// <summary>
 /// Adds a single job to cron.
 /// </summary>
 /// <param name="Job">Job to add to cron.</param>
 public void AddJob(CronJob Job)
 {
     AddJobs(new List <CronJob>()
     {
         Job
     });
 }
Example #2
0
        /// <summary>
        /// Thread that is waiting for signals to perform checks.
        /// </summary>
        private void ExecutiveThread()
        {
            log.Info("()");

            executiveThreadFinished.Reset();

            List <WaitHandle> handleList = new List <WaitHandle>();

            handleList.Add(ShutdownSignaling.ShutdownEvent);
            handleList.Add(newJobEvent);

            WaitHandle[] handles = handleList.ToArray();

            while (!ShutdownSignaling.IsShutdown)
            {
                log.Info("Waiting for event.");

                int index = WaitHandle.WaitAny(handles);
                if (handles[index] == ShutdownSignaling.ShutdownEvent)
                {
                    log.Info("Shutdown detected.");
                    break;
                }

                if (handles[index] == newJobEvent)
                {
                    handleList.Clear();
                    handleList.Add(ShutdownSignaling.ShutdownEvent);
                    handleList.Add(newJobEvent);

                    lock (jobsLock)
                    {
                        foreach (CronJob cronJob in jobs.Values)
                        {
                            handleList.Add(cronJob.Event);
                        }
                    }

                    handles = handleList.ToArray();
                    continue;
                }

                CronJob job = null;
                lock (jobsLock)
                {
                    foreach (CronJob cronJob in jobs.Values)
                    {
                        if (handles[index] == cronJob.Event)
                        {
                            job = cronJob;
                            break;
                        }
                    }
                }

                log.Trace("Job '{0}' activated.", job.Name);
                job.HandlerAsync();
            }

            executiveThreadFinished.Set();

            log.Info("(-)");
        }