string key = ConfigurationManager.AppSettings["APIKey"]; int batchSize = int.Parse(ConfigurationManager.AppSettings["BatchSize"].Trim()); Object lockMe = new Object(); PROD_Transform_MovexEntities objEntities = new PROD_Transform_MovexEntities(); var selected = (from cus in objEntities.OCUSAD_LongLat where !cus.OPCUA1.StartsWith("PICK UP") && !cus.OPCUA2.StartsWith("PO BOX") && cus.Cust_Long == null && cus.Match_Date == null select cus).Take(batchSize); List<CustomerAddress> lstResult = new List<CustomerAddress>(batchSize); //Is this OK ? Parallel.ForEach(selected, new ParallelOptions() { MaxDegreeOfParallelism = 10 }, sel => { CustomerAddress objThisCus = new CustomerAddress(); objThisCus.CustomerNumber = sel.OPCUNO; objThisCus.AddressRT = sel.OPADRT; objThisCus.AddressID = sel.OPADID; try { string address = sel.OPCUA2 + " " + sel.OPCUA3 + " " + sel.OPCUA4; GeoDetail objResult = GetGeoDetails(key, address); // Get Geocodes from Google MAPs API call objThisCus.Latitude = objResult.Latitude; objThisCus.Longitude = objResult.Longitude; objThisCus.AddressType = objResult.AddressType; if(objResult.Error.ToUpper()!="OVER_QUERY_LIMIT") { lock (lockMe) { lstResult.Add(objThisCus); } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } });
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)