public static string StartAsyncHttpResponse() { try { SqlQueries.Project_Main_Tbl selectDevTableObj = new SqlQueries.Project_Main_Tbl(); DataTable dt = new DataTable(); dt = selectDevTableObj.PingCheck(); string[] urls = { "" }; string[] projectIdToIgnoreFromPing = ConfigurationManager.AppSettings["projectsToIgnorePingCheck"].Replace(" ", "").Split(','); if (dt != null) { if (dt.Rows.Count > 0) { string returnStatus = string.Empty; List<string> urlList = new List<string>(); List<string> projectNameList = new List<string>(); List<string> projectIdList = new List<string>(); for (int i = 0; i < dt.Rows.Count; i++) { //Uri url = null; string urlData = dt.Rows[i]["live_url"].ToString(); string projectName = dt.Rows[i]["name"].ToString(); string projectId = dt.Rows[i]["id"].ToString(); if (!string.IsNullOrEmpty(urlData) && !projectIdToIgnoreFromPing.Contains(projectId.Trim())) { urlList.Add(urlData); projectNameList.Add(projectName); projectIdList.Add(projectId); } } Task[] taskList = new Task[urlList.Count]; for (int i = 0; i < urlList.Count; i++) { var index = i; //GetAsync(urlList[index], projectNameList[index], projectIdList[index]); taskList[i] = Task.Factory.StartNew(() => (GetAsync(urlList[index], projectNameList[index], projectIdList[index]))); } try { Task.WaitAll(taskList); returnStatus = "Completed"; } catch (AggregateException ae) { ErrorLogging.WriteErrorLog(ae); returnStatus = ae.ToString(); } catch (Exception ex) { ErrorLogging.WriteErrorLog(ex); returnStatus = ex.ToString(); } return returnStatus; } else //return "Completed"; return "No Live Campaigns"; } else return "No Live Campaigns"; } catch (Exception exe) { ErrorLogging.WriteErrorLog(exe); return exe.ToString(); } }