问题
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.
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.
I guess there is something like Timeout, which kills the thread. Does anyone have the same issue? Any solutions?
回答1:
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.
When there are any changes in websites bin folder, IIS will renew the AppDomain (or ApplicationPool?). That will abort current running threads.
来源:https://stackoverflow.com/questions/51940607/thread-was-being-aborted-exception-raised-in-excuting-hangfire-job