Skip to main content
Added running example.
Source Link
public static async Task PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item => item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(pointpointTask => { item.MDM_Latitude = pointpointTask.Result.Latitude.ToString(); item.MDM_Longitude = pointpointTask.Result.Longitude.ToString(); })); // Non-blocking await for tasks completion await Task.WhenAll(tasks); // Iterate to append Lat and Long 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)); } 
public static void PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item => item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(pointpointTask => { item.MDM_Latitude = pointpointTask.Result.Latitude.ToString(); item.MDM_Longitude = pointpointTask.Result.Longitude.ToString(); })); // Wait for tasks completion (it will block the current thread) Task.WaitAll(tasks.ToArray()); // Iterate to append Lat and Long 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)); } 

Running example of this last code sample: https://ideone.com/0uXGlG

public static async Task PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item => item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(point => { item.MDM_Latitude = point.Latitude.ToString(); item.MDM_Longitude = point.Longitude.ToString(); })); // Non-blocking await for tasks completion await Task.WhenAll(tasks); // Iterate to append Lat and Long 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)); } 
public static void PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item => item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(point => { item.MDM_Latitude = point.Latitude.ToString(); item.MDM_Longitude = point.Longitude.ToString(); })); // Wait for tasks completion (it will block the current thread) Task.WaitAll(tasks.ToArray()); // Iterate to append Lat and Long 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)); } 
public static async Task PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item => item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(pointTask => { item.MDM_Latitude = pointTask.Result.Latitude.ToString(); item.MDM_Longitude = pointTask.Result.Longitude.ToString(); })); // Non-blocking await for tasks completion await Task.WhenAll(tasks); // Iterate to append Lat and Long 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)); } 
public static void PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item => item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(pointTask => { item.MDM_Latitude = pointTask.Result.Latitude.ToString(); item.MDM_Longitude = pointTask.Result.Longitude.ToString(); })); // Wait for tasks completion (it will block the current thread) Task.WaitAll(tasks.ToArray()); // Iterate to append Lat and Long 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)); } 

Running example of this last code sample: https://ideone.com/0uXGlG

Fixed variable names.
Source Link
public static async Task PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item => item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(mapPointpoint => { item.MDM_Latitude = point.Latitude.ToString(); item.MDM_Longitude = point.Longitude.ToString(); })); // Non-blocking await for tasks completion await Task.WhenAll(tasks); // Iterate to append Lat and Long 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)); } 
public static void PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item => item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(mapPointpoint => { item.MDM_Latitude = point.Latitude.ToString(); item.MDM_Longitude = point.Longitude.ToString(); })); // Wait for tasks completion (it will block the current thread) Task.WaitAll(tasks.ToArray()); // Iterate to append Lat and Long 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)); } 
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(); })); // Non-blocking await for tasks completion await Task.WhenAll(tasks); // Iterate to append Lat and Long 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)); } 
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 (it will block the current thread) Task.WaitAll(tasks.ToArray()); // Iterate to append Lat and Long 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)); } 
public static async Task PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item => item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(point => { item.MDM_Latitude = point.Latitude.ToString(); item.MDM_Longitude = point.Longitude.ToString(); })); // Non-blocking await for tasks completion await Task.WhenAll(tasks); // Iterate to append Lat and Long 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)); } 
public static void PullInfo() { // Create tasks to update items with latitude and longitude var tasks = SAPItems.Where(item => item.Latitude == null || item.Longitude == null) .Select(item => GetMapPoint(item.AddressLine1 + " " + item.FiveDigitZip) .ContinueWith(point => { item.MDM_Latitude = point.Latitude.ToString(); item.MDM_Longitude = point.Longitude.ToString(); })); // Wait for tasks completion (it will block the current thread) Task.WaitAll(tasks.ToArray()); // Iterate to append Lat and Long 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)); } 
Improved comments.
Source Link
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(); })); // AwaitNon-blocking await for tasks completion await Task.WhenAll(tasks); // Iterate to append Lat and Long 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)); } 
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(it blockingwill block the current thread) Task.WaitAll(tasks.ToArray()); // Iterate to append Lat and Long 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)); } 
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)); } 
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)); } 
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(); })); // Non-blocking await for tasks completion await Task.WhenAll(tasks); // Iterate to append Lat and Long 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)); } 
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 (it will block the current thread) Task.WaitAll(tasks.ToArray()); // Iterate to append Lat and Long 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)); } 
Source Link
Loading