BackgroundWorker的线程在ASP.NET [英] BackgroundWorker thread in ASP.NET

查看:248
本文介绍了BackgroundWorker的线程在ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能使用的BackgroundWorker线程 ASP.NET 2.0以下情形,这样,在浏览器的端用户不必等待很长时间?

Is it possible to use BackGroundWorker thread in ASP.NET 2.0 for the following scenario, so that the user at the browser's end does not have to wait for long time?


  1. 浏览器请求一个页面,说SendEmails.aspx

  2. SendEmails.aspx页面创建一个BackgroundWorker的线程,并有足够的情况下提供线程创建和发送电子邮件。

  3. 浏览器接收来自ComposeAndSendEmails.aspx的反应,他说,电子邮件被发送。

  4. 同时,后台线程从事创建和发送这可能需要相当长的时间来完成的电子邮件的处理。

我最关心的是关于保持的BackgroundWorker线程中运行,要发送的,说50的电子邮件,而ASP.NET workerprocess线程池线程早已逝去。

My main concern is about keeping the BackgroundWorker thread running, trying to send, say 50 emails while the ASP.NET workerprocess threadpool thread is long gone.

推荐答案

如果你不希望使用AJAX库,或电子邮件的处理真的很长,并会超时一个标准的AJAX请求,您可以使用AsynchronousPostBack方法是老黑客,在NET 1.1天。

If you don't want to use the AJAX libraries, or the e-mail processing is REALLY long and would timeout a standard AJAX request, you can use an AsynchronousPostBack method that was the "old hack" in the .net 1.1 days.

实际上你做的是有你的提交按钮开始邮件处理异步状态,而用户带到一个中间页。这样做的好处是,你可以有你的中间页面刷新不亚于需要,无需担心命中标准超时。

Essentially what you do is have your submit button begin the e-mail processing in an asynchronous state, while the user is taken to an intermediate page. The benefit to this is that you can have your intermediate page refresh as much as needed, without worrying about hitting the standard timeouts.

当您的背景过程完成后,它会把一个小做国旗在数据库/应用程序变量/什么。当您的中间页面做的本身就是一个刷新,它检测到这个标志,并自动将用户重定向到完成页面。

When your background process is complete, it will put a little "done" flag in the database/application variable/whatever. When your intermediate page does a refresh of itself, it detects this flag and automatically redirects the user to the "done" page.

再次AJAX使得这一切毫无意义的,但如果由于某种原因,你必须有在网上做了非常密集的或及时的过程中,这种解决方案会为你工作。我找到了一个不错的教程就可以了这里,并有大量更多在那里。

Again, AJAX makes all of this moot, but if for some reason you have a very intensive or timely process that has to be done over the web, this solution will work for you. I found a nice tutorial on it here and there are plenty more out there.

我不得不用这样一个过程,当我们上与第三方应用和其进口的API接口一个网上办理登机手续的类型的应用程序的工作是可怕缓慢。

I had to use a process like this when we were working on a "web check-in" type application that was interfacing with a third party application and their import API was hideously slow.

编辑:GAH!诅咒你Guzlar和你的上帝般的打字能力8 ^ D。

GAH! Curse you Guzlar and your god-like typing abilities 8^D.

这篇关于BackgroundWorker的线程在ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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