Esempio n. 1
0
File: Idler.cs Progetto: Kidify/L4p
 private void stop_job(IdlerAction job, TimeSpan stopSpan)
 {
     using (var stopEvent = new ManualResetEvent(false))
     {
         job.Timer.Dispose(stopEvent);
         stopEvent.WaitOne(stopSpan);
     }
 }
Esempio n. 2
0
File: Idler.cs Progetto: Kidify/L4p
        private void add_job(IdlerAction job)
        {
            lock (this)
            {
                var list = new List<IdlerAction>(_jobs);
                list.Add(job);

                _jobs = list.ToArray();
            }
        }
Esempio n. 3
0
File: Idler.cs Progetto: Kidify/L4p
        private void idle_job(IdlerAction job)
        {
            int concurrentJobs = Interlocked.Increment(ref job.Mutex);

            try
            {
                if (concurrentJobs > 1)
                {
                    Interlocked.Increment(ref job.SkippedExecutions);
                    Interlocked.Increment(ref _counters.JobsSkipped);
                    return;
                }

                job.Action();
                Interlocked.Increment(ref job.SuccessfulExecutions);
                Interlocked.Increment(ref _counters.JobsExcecuted);
            }
            catch (Exception ex)
            {
                Interlocked.Increment(ref job.FailedExecutions);
                Interlocked.Increment(ref _counters.JobsFailed);
                _log.Error(ex);
            }
            finally
            {
                Interlocked.Decrement(ref job.Mutex);
            }
        }