“线程被中止";执行Hangfire工作时出现异常 [英] "Thread was being aborted" exception raised in excuting Hangfire job

查看:416
本文介绍了“线程被中止";执行Hangfire工作时出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Hangfire(使用SqlServer进行持久化)作业,该作业从数据库中查询一些数据.然后使用这些数据生成带有NPOI的Excel,然后通过电子邮件将其发送给用户.

I have a Hangfire (with SqlServer for persistence) job which query some data from database. Then generate an Excel with NPOI with these data, and sent it via Email to users.

数据不是很大,只有1,000行.因此,作业将在几秒钟内执行.但是,生成Excel或发送邮件时,出现线程被中止"异常.

The data is not so large, only like 1,000 rows. So the job executes in seconds. However, I get "Thread was being aborted" exception when generating Excel or sending mail.

我猜想像Timeout这样的东西会杀死线程. 有人有同样的问题吗?有解决方案吗?

I guess there is something like Timeout, which kills the thread. Does anyone have the same issue? Any solutions?

推荐答案

好的.实际上,我在这里犯了一个愚蠢的错误. 在生成Excel之前,我有一个模板.模板将首先复制到HttpRuntime.BinDirectory(我正在尝试避免资源冲突). HttpRuntime.BinDirectory是导致线程中止的根本原因.

Alright. Actually I made a stupid mistake in here. Before I generate an Excel, I have a template. The template will be copied to HttpRuntime.BinDirectory first (I am trying to avoid the resource conflict). This HttpRuntime.BinDirectory is the root cause which makes the thread aborted.

网站bin文件夹中有任何更改时,IIS都会续订AppDomain(或ApplicationPool?).这将中止当前正在运行的线程.

When there are any changes in websites bin folder, IIS will renew the AppDomain (or ApplicationPool?). That will abort current running threads.

这篇关于“线程被中止";执行Hangfire工作时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆