From d22c5c1861c34f0d1924efdb324e6917dccc23ef Mon Sep 17 00:00:00 2001 From: Jim Geurts Date: Mon, 25 Feb 2013 10:58:08 -0600 Subject: [PATCH] Add a comment for RunningSchedules and changed type from IList to Schedule[]. --- ConsoleTester/Program.cs | 11 ++++++++++- FluentScheduler/TaskManager.cs | 7 +++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/ConsoleTester/Program.cs b/ConsoleTester/Program.cs index 38c39677..3fa225b9 100644 --- a/ConsoleTester/Program.cs +++ b/ConsoleTester/Program.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; using FluentScheduler; @@ -55,15 +57,22 @@ public MyRegistry() Schedule(() => { + if (TaskManager.RunningSchedules.Any(x => x.Name == "Sleepy Task")) + { + Console.WriteLine("Skipped named task because sleepy task is running"); + return; + } Console.WriteLine(); Console.WriteLine("... named task output ..."); Console.WriteLine(); + + }).WithName("named task").ToRunEvery(1).Years(); Schedule(() => { Console.WriteLine("Before sleep - " + DateTime.Now); - Console.WriteLine("Running Tasks: " + TaskManager.RunningSchedules.Count); + Console.WriteLine("Running Tasks: " + TaskManager.RunningSchedules.Length); Thread.Sleep(4000); Console.WriteLine("After sleep - " + DateTime.Now); diff --git a/FluentScheduler/TaskManager.cs b/FluentScheduler/TaskManager.cs index b6b78c48..8fb0751d 100644 --- a/FluentScheduler/TaskManager.cs +++ b/FluentScheduler/TaskManager.cs @@ -22,11 +22,14 @@ public static class TaskManager private static Timer _timer; private static readonly ConcurrentDictionary RunningNonReentrantTasks = new ConcurrentDictionary(); private static readonly ConcurrentDictionary _runningSchedules = new ConcurrentDictionary(); - public static IList RunningSchedules + /// + /// Gets a list of currently schedules currently executing. + /// + public static Schedule[] RunningSchedules { get { - return new List(_runningSchedules.Values); + return _runningSchedules.Values.ToArray(); } }