UsingBingMaps.Helpers.RouteCalculator.client_GeocodeCompleted C# (CSharp) Method

client_GeocodeCompleted() private method

private client_GeocodeCompleted ( object sender, GeocodeCompletedEventArgs e ) : void
sender object
e GeocodeCompletedEventArgs
return void
        private void client_GeocodeCompleted(object sender, GeocodeCompletedEventArgs e)
        {
            try
            {
                RoutingState state = e.UserState as RoutingState;
                GeocodeResult result = null;

                lock (StateSync)
                {
                    if (_geoFailed)
                        return;
                }

                if (e.Result.ResponseSummary.StatusCode != Bing.Geocode.ResponseStatusCode.Success ||
                    e.Result.Results.Count == 0)
                {
                    lock (StateSync)
                    {
                        _geoFailed = true;
                    }

                    // Report geocode error.
                    _uiDispatcher.BeginInvoke(() => Error(new RouteCalculationError(e)));

                    return;
                }

                bool doneGeocoding = false;

                lock (StateSync)
                {
                    // Only report on first result.
                    result = e.Result.Results.First();

                    // Update state object ... when all the results are set, call route.
                    state.Results[state.LocationNumber] = result;
                    doneGeocoding = state.GeocodesComplete;
                }

                if (doneGeocoding && state.GeocodesSuccessful)
                {
                    // Calculate the route.
                    CalculateRoute(state.Results);
                }
            }
            catch (Exception ex)
            {
                lock (StateSync)
                {
                    _geoFailed = true;
                }

                _uiDispatcher.BeginInvoke(() => Error(new RouteCalculationError(ex.Message, ex)));
            }
        }