public void ExecuteInstanceQueries(int instanceId) { using (_sqlConnection) { List <Task> tasks = new List <Task>() { Task.Factory.StartNew(() => { getBaseInstanceInfo.Run(); Instance instance = getBaseInstanceInfo.Instance; instance.Id = instanceId; instance.Modified = DateTime.Now; repositoryAccess.UpdateInstance(instance); }), Task.Factory.StartNew(() => { getListofDatabases.Run(); List <Database> dbList = getListofDatabases.DbList; DatabaseQueriesExecutor dbExecutor = new DatabaseQueriesExecutor(_sqlConnection, dbList, instanceId); dbExecutor.ExecuteDatabaseQueries(); }) }; Task.WaitAll(tasks.ToArray()); } }
public static void CollectData() { List <InstanceInfo> listInstanceInfos = repositoryAccess.GetAllInstanceInfo(); var tasks = new List <Task>(); listInstanceInfos.ForEach((instanceInfo) => tasks.Add(Task.Factory.StartNew(() => { SqlConnection instanceConnection; try { instanceConnection = manager.GetOpenedInstanceConnection(instanceInfo); } catch (SqlException) { repositoryAccess.UpdateInstance(instanceInfo); return; } DataCollectorQueryExecutor queryExecutor = new DataCollectorQueryExecutor(instanceConnection); queryExecutor.ExecuteInstanceQueries(instanceInfo.Id); } ))); Task.WaitAll(tasks.ToArray()); }