/// <summary> /// Split the list of addresses into 1000-or-fewer length chunks and send them to API /// </summary> /// <param name="addressList">AddressList of any size</param> /// <returns>List of geocoded Addresses</returns> private List <Address> BulkGeoCodeSplit(AddressList addressList) { var addressResponse = new List <AddressApiResponse>(); var addressListSplit = new List <List <Address> >(); for (int i = 0; i < addressList.Addresses.Count(); i += 1000) { var newList = new AddressList(); var remainder = addressList.Addresses.Count % 1000; var offset = (remainder != 0 && i < addressList.Addresses.Count - remainder) ? 1000 : remainder; addressListSplit.Add(new List <Address>(addressList.Addresses.GetRange(i, offset))); } Parallel.ForEach(addressListSplit, subList => { var response = _apiAgent.BulkGeocode(subList); addressResponse.AddRange(response); }); return(addressResponse.Select(response => response.Address).ToList()); }