解决aspnet中“Thread was being aborted.”

一、系统环境
开发环境
1、操作系统:Windows10 Business 64bit,内存8G
2、软件环境:Asp.Net4.0、IIS7.0、5.6.26-log MySQL Community Server
部署环境
1、操作系统:Windows7 Professional 32bit,内存:4G
2、软件环境:Asp.Net4.0、IIS7.0、5.6.26-log MySQL Community Server

二、问题描述
程序在[开发环境]正常运行
程序在[部署环境]中IIS配置可以正常访问aspx页面,无容器级别的BUG,但是在导出数据时,运行1~2min开始报以下错误:

[2018-10-16 14:25:08,694][7792][ERROR][JH.LDR.Web.Ajax.AjaxJsonBase]-HOST:::1,MAC:10-E7-C6-B3-29-E0,ERROR:Thread was being aborted.
[2018-10-16 14:25:09,077][7792][ERROR][JH.LDR.Web.Ajax.AjaxJsonBase]- at System.Array.Copy(Array sourceArray, Int32 sourceIndex, Array destinationArray, Int32 destinationIndex, Int32 length, Boolean reliable)
at System.Collections.Generic.List`1.set_Capacity(Int32 value)
at System.Collections.Generic.List`1.EnsureCapacity(Int32 min)
at System.Collections.Generic.List`1.Add(T item)
at System.Text.RegularExpressions.RegexNode.AddChild(RegexNode newChild)
at System.Text.RegularExpressions.RegexParser.ScanRegex()
at System.Text.RegularExpressions.RegexParser.Parse(String re, RegexOptions op)
at System.Text.RegularExpressions.Regex..ctor(String pattern, RegexOptions options, Boolean useCache)
at JH.LDR.Common.NPOIHelper.isNumeric(String message, Double& result)
at JH.LDR.Common.NPOIHelper.ExportDTI(DataTable dtSource, String strHeaderText, FileStream fs)
at JH.LDR.Common.NPOIHelper.ExportDTtoExcel(DataTable dtSource, String strHeaderText, String strFileName)
[2018-10-17 10:42:52,070][4556][ERROR][JH.LDR.Web.Ajax.AjaxJsonBase]-HOST:::1,MAC:10-E7-C6-B3-29-E0,ERROR:Thread was being aborted.
[2018-10-17 10:42:52,196][4556][ERROR][JH.LDR.Web.Ajax.AjaxJsonBase]- at System.Threading.Monitor.ReliableEnter(Object obj, Boolean& lockTaken)
[2018-10-19 10:48:54,433][3928][ERROR][JH.LDR.Web.Ajax.AjaxJsonBase]-HOST:::1,MAC:10-E7-C6-B3-29-E0,ERROR:Thread was being aborted.
[2018-10-19 10:48:54,796][3928][ERROR][JH.LDR.Web.Ajax.AjaxJsonBase]- at MyNetworkStream.HandleOrRethrowException(Exception e)

三、解决办法及思路
1、首先每次报错都有“ERROR:Thread was being aborted”,但细节错误不一样,起初认为是IIS内存不够导致,因为导出数据量较多;修改导出方案为分批次导出数据,报错依旧
2、修改IIS的虚拟内存使用情况及专用内存使用情况:1024*1024=1048576(KB),错误依旧
3、通过虚拟机模拟部署环境:可以正常导出。
操作系统:Windows7 Professional 32bit,内存:2G
软件环境:Asp.Net4.0、IIS7.0

4、Google“asp.net Thread was being aborted”找到参考资料[1]得到启发,根据参考资料[2]在web.cofnig配置<system.web>节点增加相关配置,成功导出数据
<system.web>
    <httpRuntime maxRequestLength="102400" executionTimeout="720" />
</system.web>
参考资料[3]中为页面跳转时错误,可以通过try,catch搞定;该程序未涉及,但网上转发较多
步骤如有遗漏,请多指教
四、参考资料
1、Why am i getting “Thread was being aborted” in asp.net?
2、如何设置ASP.NET页面的运行超时时间
3、Thread was being aborted 分析与解决

发表评论

电子邮件地址不会被公开。 必填项已用*标注