Skip to content

Instantly share code, notes, and snippets.

@BryanWilhite
Last active August 29, 2015 14:09
Show Gist options
  • Save BryanWilhite/6e8f07f61eb1418df7d4 to your computer and use it in GitHub Desktop.
Save BryanWilhite/6e8f07f61eb1418df7d4 to your computer and use it in GitHub Desktop.
C#, TPL, Quartz.NET: Array-Driven Tasks
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