从 ASP.NET 页面运行长进程的方法

发布于 2024-08-21 12:14:44 字数 104 浏览 7 评论 0原文

在 asp.net 中运行较长的流程(例如 2 小时)并将进度信息返回给客户端的最成功方法是什么。

我听说创建 Windows 服务、httphandler 和远程处理可以成功。

What are your most successful ways of running a long process, like 2 hours, in asp.net and return information to the client on the progress.

I've heard creating a windows service, httphandler and remoting can be successful.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

烏雲後面有陽光 2024-08-28 12:14:44

只是一个建议...

如果您已经在 ASP.NET 中尝试使用逻辑...您可以创建一个外部应用程序(Windows 服务、控制台应用程序等)来调用 ASP.NET 上的 Web 服务页。

例如,我遇到了一个类似的问题,我需要的代码是 asp.net,并且我需要使用此代码更新大约 3000 个客户端。它开始超时,所以我通过网络服务公开了代码。然后,我没有尝试通过 asp.net 一次性运行全部 3000 个客户端,而是使用了一个由夜间 sql 服务器作业运行的控制台应用程序,该作业为每个客户端运行一次 Web 服务。这样,所有耗时的处理都由控制台应用程序处理,不存在超时问题,但我们已经在 ASP.NET 中编写的代码不必重新创建。最后稍微修改现有架构的设计让我轻松解决了这个问题。

这实际上取决于您必须处理的环境和限制...希望这会有所帮助。

Just a suggestion...

If you have logic that you are tyring to utilize already in asp.net... You could make an external app (windows service, console app, etc.) that calls a web service on your asp.net page.

For example, I had a similiar problem where the code I needed was asp.net and I needed to update about 3000 clients using this code. It started timing out, so I exposed the code through a web service. Then, instead of trying to run the whole 3000 clients at through asp.net all at once, I used a console app that is run by a nightly sql server job that ran the web service once for each client. This way all the time consuming processing was handled by the console app that doesn't have the time out issue, but the code we had already wrote in asp.net did not have to be recreated. In the end slighty modifying the design of my existing architecture allowed me easily get around this problem.

It really depends on the environment and constraints you have to deal with...Hope this helps.

怎樣才叫好 2024-08-28 12:14:44

我有两种方法来处理这个问题。首先,您可以简单地运行该进程并让客户端超时。这有两个缺点:UI 不同步,并且您将 IIS 线程用于非 html 目的(我这样做是为了一个过去返回足够快但增长超出超时限制的进程)。

处理此问题的更好方法是编写一个“服务”应用程序,该应用程序处理通过数据库表传递的请求(将请求的详细信息放在那里)。然后,您可以创建一个窗口,为用户提供一个了解任务正在进行的进度的“窗口”(例如,已处理多少记录或发送了多少电子邮件)。此状态窗口可以具有允许用户刷新的链接,也可以使用计时器上的 Ajax 回调自动刷新。

There are two ways that I have handled this. First, you can simply run the process and let the client time out. This has two drawbacks: the UI isn't in synch and you are tying up an IIS thread for non-html purposes (I did this for a process that used to return quickly enough but that grew beyond time-out limits).

The better way to handle this is to write a "Service" application that handles the request as passed through a database table (put the details of the request there). Then you can create a window that gives the user a "window" into ongoing progress on the task (e.g. how many records have been processed or emails sent). This status window can either have a link to permit the user to refresh or you can automate the refresh using Ajax callbacks on a timer.

眉目亦如画i 2024-08-28 12:14:44

这并不直接适用,但我编写的代码可以让您在 ASP.NET 内部运行类似于“计划任务”的进程,而无需使用 Windows 服务或任何类型的 cron 作业。

ASP.NET 中的计划任务!

This isn't directly applicable but I wrote code that will let you run processes similar to "scheduled tasks" inside of ASP.NET without needing to use windows services or any type of cron jobs.

Scheduled Tasks in ASP.NET!

太傻旳人生 2024-08-28 12:14:44

与计划任务相比,我更喜欢 WCF 服务。您可能(我突然想到)将 addr 作为一种“回调”传递给 WCF 服务,服务可以在工作时使用进度报告来调用该回调。

我会回避预定的任务……太粗粒度了。

I very much prefer WCF service to scheduled tasks. You might (off the top of my head) pass an addr to the WCF service as a sort of 'callback' that the service can call with progress reports as it works.

I'd shy away from scheduled tasks... too course grained.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文