using System.Threading.Tasks;
using System.Collections.Generic;
using System.Diagnostics;
public static void Main()
private async static void DoSomething()
List<ILoader> loaderList = new List<ILoader>() { new LoaderA(), new LoaderB(), new LoaderC() };
Stopwatch stopwatch = new Stopwatch();
Console.WriteLine("Loaders Registered:\n-------------------");
foreach (var x in loaderList) Console.WriteLine("\t" + x.GetType().Name);
Console.WriteLine("\nLoaders Executed:\n-----------------");
var taskList = loaderList.Select(loader => {
var loaderName = loader.GetType().Name;
var myDictionaryTask = loader.LoadSomething(loaderName);
if (myDictionaryTask.IsFaulted || myDictionaryTask.Result == null)
Console.WriteLine("\t" + loaderName + ": returned null");
Console.WriteLine("\t" + loaderName + ": returned with " + myDictionaryTask.Result.Count() + " value");
await Task.WhenAll(taskList);
Console.WriteLine("\nTime elapsed: {0}", stopwatch.Elapsed);
Task<Dictionary<string, string>> LoadSomething(string keyValue);
public class LoaderA : ILoader
public async Task<Dictionary<string, string>> LoadSomething(string keyValue)
var dictionary = new Dictionary<string, string>()
System.Threading.Thread.Sleep(1000);
Console.WriteLine("\tLoaderA => Called Once");
public class LoaderB : ILoader
public async Task<Dictionary<string, string>> LoadSomething(string keyValue)
Dictionary<string, string> dictionary = null;
System.Threading.Thread.Sleep(1000);
Console.WriteLine("\tLoaderB => Called Once");
public class LoaderC : ILoader
public async Task<Dictionary<string, string>> LoadSomething(string keyValue)
var dictionary = new Dictionary<string, string>()
System.Threading.Thread.Sleep(1000);
Console.WriteLine("\tLoaderC => Called Once");