简体   繁体   English

函数中出现意外的ThreadAbortException

[英]Unexpected ThreadAbortException in a function

We have an application that calls a function after interval of 5 minutes(using timer) from Glabal.asax 我们有一个应用程序,它间隔5分钟(使用计时器)从Glabal.asax中调用一个函数

The function communicates with third parties, gets data and sends it to another application that updates the database. 该功能与第三方通信,获取数据并将其发送到另一个更新数据库的应用程序。

After 4th or 5th time the function is called, a ThreadAbortException is called while receiving data from 3rd party application. 在第4次或第5次调用该函数之后,在从第3方应用程序接收数据时将调用ThreadAbortException。 This stops the entire application. 这将停止整个应用程序。

We don't use Response.End, Response.Redirect or Server.Transfer which are the functions that cause ThreadAbortException. 我们不使用会导致ThreadAbortException的函数Response.End,Response.Redirect或Server.Transfer。

Application pool might get restarted/recycled. 应用程序池可能会重新启动/回收。 But what can be cause of this? 但是,这可能是什么原因呢? I changed the timeout to 0 which means it will never timeout. 我将超时更改为0,这意味着它将永远不会超时。 But I am still getting the exception. 但我仍然遇到例外。

Can anyone suggest anything? 有人可以建议什么吗?

Thanks. 谢谢。

I was using a WebRequest object to make request to the third party. 我正在使用WebRequest对象向第三方发出请求。 The solution to the problem is to change the timeout of the request. 解决该问题的方法是更改​​请求的超时。 I changed it to infinite. 我将其更改为无限。

WebRequest request = WebRequest.Create(serviceUrl);
request.Method = "POST";
request.Timeout = System.Threading.Timeout.Infinite;

I hope this helps someone who encounters similar situation. 我希望这对遇到类似情况的人有所帮助。 I was helped by my colleague though. 不过我得到了同事的帮助。

Edit - I also found an interesting article on MSDN - Understanding WebRequest Problems and Exceptions 编辑-我还在MSDN上找到了一篇有趣的文章- 了解WebRequest问题和异常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM