private static List <OfficeContactCollection> GetOfficeContacts(string userName, string password, int numberOfContacts) { // this is the list that will hold all the contacts that are returned List <OfficeContactCollection> tempOfficeContactsList = new List <OfficeContactCollection>(); List <Task <OfficeContactCollection> > taskCollection = new List <Task <OfficeContactCollection> >(); // keep going while there are more contacts to be retrieved int officeContactCount = 0; try { while (officeContactCount < numberOfContacts) { taskCollection.Add(OfficeAPIRead.GetContactList(userName, password, officeContactCount)); officeContactCount += 50; } // wait for them to all show up Task.WaitAll(taskCollection.ToArray()); } catch { Console.WriteLine("This Account Information Is Incorrect! for this user:\n" + userName); } taskCollection.ToString(); // add to the contact list collection foreach (Task <OfficeContactCollection> task in taskCollection) { tempOfficeContactsList.Add(task.Result); } return(tempOfficeContactsList); }
private static async Task <int> GetNumbumberOfOfficeContacts(string userName, string password) { // hold the number of contacts in the list int numberOfOfficeContacts = new int(); // find out how many contacts there are numberOfOfficeContacts = await OfficeAPIRead.GetNumberOfContacts(userName, password); return(numberOfOfficeContacts); }