响应时,线程被中止.GetResponseStream()

时间:2015-05-20 06:21:09

标签: c# asynchronous

我是异步调用的新手请帮我更新我的代码与async mehtod这是最好的方法 请建议

以下是我的代码

        private string GetTranslatedContent(RequestModel oRequestModel, string contentToTranslate)
    {
        string translatedContent = null;
        string uri ="http://sample.com/test/getTranslatedcontent/";
        try
        {
            if (!string.IsNullOrEmpty(contentToTranslate))
            {
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri+contentToTranslate);  
                var response = httpWebRequest.GetResponse();
                using (var stream = response.GetResponseStream())
                {
                    //here i got translatedContent and  return to caller method
                }
            }
        }
        catch (Exception ex)
        {

        }
        return translatedContent;
      }

此方法从下面的方法调用,并将updatedContent返回到数据库中以获取该特定记录ID

public void TranslateALLDATA()
            {
            ItemsCollection = getDATAFromDBToTranslate();
            foreach (item item in ItemsCollection)
            {
                if (!string.IsNullOrEmpty(item.text))
                {
                    translatedcontnet = GetTranslatedContent(oRequestModel, item.text);
                    //after that update record in table for that item
                    update table text=translatedcontnet where id= item.id;
                }
            }
            }

0 个答案:

没有答案