Last active
August 29, 2015 14:09
-
-
Save BryanWilhite/6e8f07f61eb1418df7d4 to your computer and use it in GitHub Desktop.
C#, TPL, Quartz.NET: Array-Driven Tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sample : IJob | |
{ | |
/// <summary> | |
/// Called by the <see cref="T:Quartz.IScheduler"/> when a <see cref="T:Quartz.ITrigger"/> | |
/// fires that is associated with the <see cref="T:Quartz.IJob"/>. | |
/// </summary> | |
/// <param name="context">The execution context.</param> | |
public void Execute(IJobExecutionContext context) | |
{ | |
this._settings = new ApplicationSettings(); | |
if (this._settings.UrlsForSolarEnergyReading == null) | |
throw new JobExecutionException("The expected Solar Energy Reading URIs are not here."); | |
var taskList = new List<Task>(); | |
this._settings | |
.UrlsForSolarEnergyReading | |
.ForEachInEnumerable(entry => | |
{ | |
Action a = () => this.DoRawSolarEnergyReading(entry.Key, entry.Value); | |
var t = new Task(a); | |
taskList.Add(t); | |
t.Start(); | |
}); | |
var tasks = taskList.ToArray(); | |
Task.WaitAll(tasks); | |
this.DoWeather(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment