# Run multiple prerequisite methods in parallel before continuing

I have an application in which I have multiple slow running prerequisite methods I need to call in order to have the data I need to continue.

To try to speed this up I am doing this:

Dictionary<string, string> processOptions = null;
Dictionary<string, string> requirementLevels = null;
List<TemplateSection> sections = null;
List<TemplateVersion> versions = null;



Each of the methods above can take anything from 2-5 seconds to complete. Is there a nicer way of doing this, or is this something I shouldent do?

P.S. the code as is works great and decreases the time used by around 30%.

Another option is Parallel.Invoke:

Dictionary<string, string> processOptions = null;
Dictionary<string, string> requirementLevels = null;
List<TemplateSection> sections = null;
List<TemplateVersion> versions = null;

Parallel.Invoke(() => sections = GetSectionsInTreeForm(latestVersionGuid),
() => versions = GetTemplateVersions(templateId),
() => processOptions = GetOptionSetProcessPhaseTypes(),

It should be pointed out that these tasks run in threads from the thread pool (in both cases: Task and Parallel.Invoke). That's OK for few tasks with a run time from 2-5 seconds, but for long running tasks it is better to use a Task object with TaskCreationOptions.LongRunning to run the task in it's own thread. Otherwise the threadpool threads will be blocked for other short running tasks.
Tasks provide a more granular control but that is not required in your case so I would prefer the simpler Parallel.Invoke variant.