如何实现在ASP中的WebAPI应用很长时间运行的后台任务 [英] How to implement a very long running background task in Asp WebAPI application

查看:445
本文介绍了如何实现在ASP中的WebAPI应用很长时间运行的后台任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写一个应用程序的WebAPI执行大量的长时间运行的后台处理任务。

I'm writing a WebAPI application to perform a number of long running background processing tasks.

我注意到,我的测试数据加载任务,是由System.Threading.ThreadAbortException杀害,即使我禁用IIS中的池回收。
我知道,有运行运行时间非常长(几个小时之久)背景的Web应用程序内任务的方式,但是,我只是不知道究竟怎么做到这一点 - 无论是一些特定的配置设置,编码技术,一个Wen.config参数,等等。
任何人都可以分享这样的一些实际办法,好吗?

I'm noticing, that my test data loading task, is being killed by System.Threading.ThreadAbortException, even after I disable the pool recycling in IIS. I know, that there is a way to run a very long running (a few hours long) background tasks within a Web application, but, I just do not know how exactly that is done - either some specific configuration settings, a coding technique, a Wen.config parameter, etc... Can anyone share some practical way of doing this, please?

推荐答案

你不想使用IIS / ASP.Net运行长时间运行的过程,它不是专为。

You DON'T want to use IIS/ASP.Net to run a long running process, it was not designed for that.

只用它在Web.API初始呼叫使用MSMQ或插入一行到告诉你的单独的进程做一个表,脱掉你的服务。

Only use it for the initial call in Web.API to kick off your service by using MSMQ or inserting a row into a table that tells your separate process what to do.

创建一个单独的应用程序 - 无论是控制台应用程序,在这里你可以使用Windows计划定期运行的应用程序,并检查是否有新的工作项目;或Windows服务,定期检查你的工作项目商店工作项目。然后,可以使用线程池等,以异步运行您的程序。

Create a separate application - either a Console application, where you would use Windows Scheduler to periodically run the app and check for new work items; or a Windows Service, that periodically checks your work item store for work items. You can then use the ThreadPool, etc to asynchronously run your process.

这篇关于如何实现在ASP中的WebAPI应用很长时间运行的后台任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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