// Public methods. /// <summary> /// Begins an asynchronous request for Alexa countries. /// </summary> /// <param name="callback">The callback method.</param> /// <param name="countries">The list of countries.</param> /// <param name="userState">The user state.</param> public IAsyncResult BeginGetCountries(AsyncCallback callback, AlexaCountries countries = null, object userState = null) { // Create the request state. AlexaCountriesRequestState asyncState = new AlexaCountriesRequestState(callback, countries, userState); // Call the internal request method. this.BeginGetCountriesInternal(asyncState); // Return the request state. return asyncState; }
// Private methods. /// <summary> /// Begins an asynchronous request for the Alexa countries. /// </summary> /// <param name="asyncState">The asynchronous state.</param> private void BeginGetCountriesInternal(AlexaCountriesRequestState asyncState) { // Begin an asynchronous request for the Alexa countries. asyncState.Result = base.Begin(AlexaRequest.urlCountries, (AsyncWebResult asyncResult) => { try { // The request data. string data; // Complete the request. AsyncWebResult result = base.End(asyncResult, out data); // Parse the list of countries. asyncState.Countries.Parse(data); } catch (Exception exception) { // Set the exception. asyncState.Exception = exception; } finally { // Complete the request. asyncState.Complete(); // Call the callback method. if (null != asyncState.Callback) asyncState.Callback(asyncState); // Dispose the state. asyncState.Dispose(); } }, asyncState); }