1

我正在运行一个同步作业,它将数据同步到一个 api,我每天都会收到几次 ThreadAbortException,我不知道为什么。代码看起来像这样。

var result = new TResult();

        try
        {
            using (var response = webRequest.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    if (responseStream == null)
                    {
                        return result;
                    }

                    using (var reader = new StreamReader(responseStream))
                    {
                        string content = reader.ReadToEnd();

                        result.HandleResponse(response, content);
                    }
                }

            }
        }
        catch (WebException ex)
        {
            using (var responseStream = ex.Response.GetResponseStream())
            {
                if (responseStream == null)
                {
                    result.HandleError(ex);
                }

                using (var reader = new StreamReader(responseStream))
                {
                    string content = reader.ReadToEnd();

                    result.HandleError(ex, content);
                }
            }
        }

        return result;    

这是抛出的异常:

System.Threading.ThreadAbortException: Thread was being aborted.
 at System.Net.ConnectStream.WriteHeaders(Boolean async)
 at System.Net.HttpWebRequest.EndSubmitRequest()
 at System.Net.HttpWebRequest.CheckDeferredCallDone(ConnectStream stream)
 at System.Net.HttpWebRequest.GetResponse()

我搜索了一下,大多数答案似乎都围绕着这个错误: https: //support.microsoft.com/en-us/kb/312629

错误的原因可能是什么,我应该如何避免或处理它?

4

0 回答 0