运行在ASP.Net Web应用程序后台任务,并得到反馈的最佳方式? [英] Best way to run a background task in ASP.Net web app and also get feedback?

查看:112
本文介绍了运行在ASP.Net Web应用程序后台任务,并得到反馈的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在下面的办法,但不知道如果最好的出路:

I am thinking on the following approach but not sure if its the best way out:

第一步(服务器端):一类TaskMangaer创建一个新的线程,并启动任务

步骤2(服务器端):存储TASKMANAGER对象引用到缓存中以供将来参考

步骤3(客户端):定期使用Ajax调用来检查任务的状态。

step1 (server side): A TaskMangaer class creates a new thread and start a task.
step2 (server side): Store taskManager object reference into the cache for future reference.
step3 (client side): Use periodic Ajax call to check the status of the task.

基本上,目的是为了有一个框架,运行一个后台任务(约5分钟),并在任务完成百分比的web用户界面提供定期的反馈。

Basically the intention is to have a framework to run a background task (5mins approx) and provide regular feedback on the web UI for the percentage of task completed.

有没有解决这个一个整洁的方式,或任何现有的asp.net的API,这将是有益的?

Is there a neat way around this or any existing asp.net API that will be helpful ?

修改1#:我要运行进程内与应用程序的任务。

Edit 1#: I want to run the task in-proc with the app.

编辑2#:看起来像堆栈溢出徽章实现也使用缓存来跟踪后台任务。 http://blog.stackoverflow.com/2008/07/易后台任务 - 在ASPNET /

Edit 2#: Looks like badge implementation on stack overflow is also using the cache to track background task. http://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/

推荐答案

我觉得跟结果存储在缓存中的问题是,ASP.NET可能会清除用于其它目的的缓存项(即,如果其短期记忆,如果它的脾气暴躁等)。这是从缓存中的东西应该是一些你可以根据需要重新如果不在缓存中,ASP.NET运行时是免费的转储缓存条目时感觉它。

I think the problem with storing the result in the cache is that ASP.NET might scavenge that cache entry for other purposes (ie if its short on memory, if its grumpy, etc). Something that is served from the cache should be something you can recreate on demand if its not found in the cache, the ASP.NET runtime is free to dump cache entries whenever it feels like it.

在徽章讨论缓存的使用似乎根本不同,在这种情况下,任务是短暂。高速缓存只是被用来作为哈克计时器周期性断火的任务

The usage of the cache in the badge discussion seems fundamentally different, in that case the task was shortlived. The cache was just being used as a hacky timer to fire off the task periodically.

您可以确认这是要采取5分钟的任务,需要有自己的线程全部时间?这本身就是一个性能问题,你只能够支持这种请求的数量有限,如果每个都需要有自己的线程了这么久。只有如果那是可以接受的,我会让任务阵营线程这么久。

Can you confirm this is a task that is going to take 5 minutes, and require its own thread that whole time? This is a performance concern in itself, you will only be able to support a limited number of such requests if each requires its own thread for so long. Only if thats acceptable would I let the task camp a thread for so long.

如果其确定为这些任务阵营线程,那么我只是继续前进,结果在字典全局存储的过程。字典的关键将关联到客户端请求/ AJAX回调系列。关键应包括用户ID,以及如果安全性是最重要的。

If its ok for these tasks to camp a thread, then I'd just go ahead and store the result in a dictionary global to the process. The key of the dictionary would correlate to the client request / AJAX callback series. The key should incorporate the user ID as well if security is at all important.

如果您需要扩展到很多用户,那么我认为你需要向下把任务分成异步步骤,在这种情况下,我可能会使用一个数据库表来存储结果(每个请求/用户再次键控)。

If you need to scale up to many users, then I think you need to break the task down into asynchronous steps, and in that case I'd probably use a DB table to store the results (again keyed per request / user).

这篇关于运行在ASP.Net Web应用程序后台任务,并得到反馈的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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