Webclient 实现异步调用
private void CallTaxonomyNodeAttributeApi(TaxonomyNodeAttribute taxonomyNodeAttribute) { string apiUri = string.Format(nodeAttributeURL, taxonomyNodeAttribute.NodeID); taxonomyNodeAttribute.RetryCount += 1; WebClient webClient = new WebClient(); webClient.Headers.Add("Authorization", authorizationStr); webClient.Proxy = HttpAPIClient.GetProxy(); webClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(ProcessTaxonomyAttributeResponseData); webClient.DownloadDataAsync(new Uri(apiUri), taxonomyNodeAttribute); } private void ProcessTaxonomyAttributeResponseData(object sender, DownloadDataCompletedEventArgs e) { TaxonomyNodeAttribute taxonomyNodeAttribute = e.UserState as TaxonomyNodeAttribute; if (e.Error == null) { taxonomyNodeAttribute.ResponseData = e.Result; //... } else { //... } }