private void IndexContacts() { try { List <int> accounts = GetAccounts(); Action <int> ReIndex = (id) => { Console.WriteLine("Indexing contacts now..." + DateTime.Now.ToString()); var contactsResponse = contactService.ReIndexContacts(new ReIndexContactsRequest() { AccountId = id }); Console.WriteLine("Indexing saved-searches now..." + DateTime.Now.ToString()); var savedSearchResponse = advancedSearchService.IndexSavedSearches(id); Console.WriteLine("Total contacts indexed : " + contactsResponse.IndexedContacts + " Time:" + DateTime.Now.ToString()); Console.WriteLine("Total saved-searches indexed : " + savedSearchResponse + " Time:" + DateTime.Now.ToString()); }; if (accounts != null && accounts.Any()) { foreach (var account in accounts) { ReIndex(account); } } else { //reindex all contacts ReIndex(0); } } catch (Exception e) { Console.WriteLine(e.ToString()); } }