c# - 线程被中止错误

标签 c# asp.net multithreading abort

我们有一个可以创建电子书的应用程序。 该应用程序有一个导出模块,可以创建 AIR 文件,但这可能需要一段时间(有些书有 2500 页)。 如果我们导出,我们会收到以下错误:

Thread was being aborted. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Threading.ThreadAbortException: Thread was being aborted.

Source Error: 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 

[ThreadAbortException: Thread was being aborted.]
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +501
   System.Web.ApplicationStepManager.ResumeSteps(Exception error) +564
   System.Web.HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +141
   System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr) +436

我已将运行时执行超时更改为 3600 秒,但它在 3 分钟左右一直崩溃。 所以它与时间有关......每次我们接近 3 分钟时它就会崩溃,我希望有人可以帮助我。

最佳答案

我认为保罗关于异常原因的说法是正确的。 IIS 和 ASP.NET 都有限制请求可以花费的最长时间的设置。对于 ASP.NET,它位于 Machine.Config 文件中(查找 httpRuntime 元素、executionTimeout 属性)。在我的开发机器上设置为 90 秒。

但是,我不建议您更改该设置,因为它是为了确保您的应用程序不会因错误请求而挂起。

长时间运行的任务应该使用异步执行。通过异步执行,实际工作是在单独的线程上处理的。这可以释放处理请求的线程来处理其他请求,这有利于应用程序的整体性能。

有一些关于此的好文章。例如:http://msdn.microsoft.com/en-us/magazine/cc163725.aspx

关于c# - 线程被中止错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/806229/

相关文章:

c# - Azure 数据湖存储基准

c# - PayPal SDK 未预填充的账单字段

c# - 从 Asp.net 线程池获取线程?

c# Process.GetCurrentProcess().Threads.Count 在使用 MaxDegreeOfParallelism 时未返回预期?

multithreading - Delphi XE 中的多线程有哪些新功能?

c# - 如何获取 Visual Studio Intellisense 工具提示以显示 .NET Framework 3.5 的说明?

c# - 转发 MailItem Outlook Addinn 问题

c++ - 为什么std::lock_guard在使用std::adopt_lock之后释放锁?

c# - WebControl 和 IDisposable

c# - Windows 反恶意软件扫描接口(interface) - ASP.NET/IIS