Skip to main content
1 of 4

You can get multiple map points asynchronously with multiple tasks (notice that it requires to convert PullInfo() to async-await):

public static async Task PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(mapPoint => { item.MDM_Latitude = point.Latitude.ToString(); item.MDM_Longitude = point.Longitude.ToString(); })); // Await for tasks completion await Task.WhenAll(tasks); // Iterate to append foreach(var item in SAPItems) Console.WriteLine(item.MDM_Latitude + " " + item.MDM_Longitude); } private static Task<MapPoint> GetMapPoint(string add) { return Task.Run(() => LocationService.GetLatLongFromAddress(add)); } 

If PullInfo() cannot be converted to async-await, you can force the thread to wait for the results, but it will block the current thread:

public static void PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(mapPoint => { item.MDM_Latitude = point.Latitude.ToString(); item.MDM_Longitude = point.Longitude.ToString(); })); // Wait for tasks completion by blocking the current thread Task.WaitAll(tasks.ToArray()); // Iterate to append foreach(var item in SAPItems) Console.WriteLine(item.MDM_Latitude + " " + item.MDM_Longitude); } private static Task<MapPoint> GetMapPoint(string add) { return Task.Run(() => LocationService.GetLatLongFromAddress(add)); }