using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
public async static void Main()
TimeSpan exceptionBatchTimeBudget = TimeSpan.FromSeconds(10);
var response = new List<int>();
for (var i = 0; i < 100; i++)
Console.WriteLine("Responses: {0}", response.Count);
if (response == null || response.Count == 0)
var exceptionLogIDsToProcess = response;
int totalLogsProcessed = 0;
var throttler = new SemaphoreSlim(initialCount: threads);
var timer = Stopwatch.StartNew();
Console.WriteLine("Started at {0}", DateTime.Now);
var tasks = exceptionLogIDsToProcess.Select(async exceptionLogId =>
await throttler.WaitAsync();
var queryString = new Dictionary<string, string> { { "exceptionLogID", exceptionLogId.ToString() } };
var serviceResponse = false;
AddExceptionLogIDExcludes(exceptionLogId, "VR_REGROUPING");
Console.WriteLine("Tasks: {0}", tasks.Count());
await Task.WhenAll(tasks);
Console.WriteLine("Ended at {0}", DateTime.Now);
Console.WriteLine("Fails: {0}", exceptionLogIDExcludes.Count);
if (totalLogsProcessed == 0)
private static List<exceptionLogIDExclude> exceptionLogIDExcludes = new List<exceptionLogIDExclude>();
private class exceptionLogIDExclude
public DateTime DatetimeUTC;
public string EventException;
private static void AddExceptionLogIDExcludes(int exceptionLogID, string eventException)
if (exceptionLogIDExcludes != null)
var index = exceptionLogIDExcludes.FindIndex(i => i.Id == exceptionLogID);
exceptionLogIDExcludes.ElementAt(index).Count++;
exceptionLogIDExcludes.Add(new exceptionLogIDExclude
EventException= eventException,
DatetimeUTC = DateTime.UtcNow,