Skip to content

Commit

Permalink
Add a comment for RunningSchedules and changed type from IList<Schedu…
Browse files Browse the repository at this point in the history
…le> to Schedule[].
  • Loading branch information
jgeurts committed Feb 25, 2013
1 parent a0d53bc commit d22c5c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
11 changes: 10 additions & 1 deletion ConsoleTester/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using FluentScheduler;
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions FluentScheduler/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@ public static class TaskManager
private static Timer _timer;
private static readonly ConcurrentDictionary<Action, bool> RunningNonReentrantTasks = new ConcurrentDictionary<Action, bool>();
private static readonly ConcurrentDictionary<Guid, Schedule> _runningSchedules = new ConcurrentDictionary<Guid, Schedule>();
public static IList<Schedule> RunningSchedules
/// <summary>
/// Gets a list of currently schedules currently executing.
/// </summary>
public static Schedule[] RunningSchedules
{
get
{
return new List<Schedule>(_runningSchedules.Values);
return _runningSchedules.Values.ToArray();
}
}

Expand Down

0 comments on commit d22c5c1

Please sign in to comment.