ASP.NET真正的异步操作 [英] ASP.NET true asynchronous operation

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

问题描述

我想断火从ASP.NET页几个HTTP请求。网页本身并不需要知道的反应,并应继续处理&放大器;不管提供的页面。

I'm trying to fire off several HTTP requests from an ASP.NET page. The page itself doesn't need to know the response and should continue processing & deliver the page regardless.

我试过把HTTP code在一个BackgroundWorker和异步运行它,但是我最初得到了以下错误;

I've tried putting the HTTP code in a BackgroundWorker and running it asynchronously, however I initially got the following error;

异步操作在此上下文中允许的。页开始
  异步操作必须具有异步属性设置为true
  和异步操作只能之前的页面上启动
  preRenderComplete事件。

Asynchronous operations are not allowed in this context. Page starting an asynchronous operation has to have the Async attribute set to true and an asynchronous operation can only be started on a page prior to PreRenderComplete event.

所以,我没有,因为我被告知,给了页面的异步属性。然后,我做了一些研究,发现我的BackgroundWorker没有实际执行异步操作如我所料。一些背景读数(的http://www.pluralsight-training.net/community/blogs/mike/archive/2005/11/04/16213.aspx)告诉我;

So I did as I was told and gave the page the Async attribute. I then did some research and discovered that my BackgroundWorker isn't actually performing an asynchronous operation as I expected. Some background reading (http://www.pluralsight-training.net/community/blogs/mike/archive/2005/11/04/16213.aspx) informed me that;

preRender和preRenderComplete事件[不]不能恢复,直到所有的
  所有的注册的异步任务的超时事件处理程序有
  被调用和返回。

PreRender and PreRenderComplete events [do] not resume until all of the timeout event handlers for all of the registered async tasks have been invoked and return.

如何确保我的BackgroundWorker不会中止页面的处理?

How do I ensure that my BackgroundWorker does not suspend the processing of the page?

推荐答案

来看看另一个选项是ThreadPool.QueueUserWorkitem()。它会火过的东西异步。它也将在线程的线程池asp.net使用。

Another option to look at is ThreadPool.QueueUserWorkitem(). It will fire something off asynchronously. It will also use on of the threads in the asp.net threadpool.

我通常用在GUI /的WinForms服务器和BackgroundWorker的上的线程池。这并不是说不能做。

I've typically used threadPool on the server and BackGroundWorker in gui/winforms. That's not to say it can't be done.

这至少别的尝试,如果您遇到与BackgroundWorker的...

That's at least something else to try if you get stuck with BackgroundWorker...

下面是一些其他的SO职位:

Here's a few other SO posts:

<一个href=\"http://stackoverflow.com/questions/6962877/threadpool-queueuserworkitem-uses-asp-net\">ThreadPool.QueueUserWorkItem使用ASP.Net

<一个href=\"http://stackoverflow.com/questions/738139/threadpool-queueuserworkitem-with-a-lambda-ex$p$pssion-and-anonymous-method\">ThreadPool.QueueUserWorkItem用一个lambda前pression和匿名方法

<一个href=\"http://stackoverflow.com/questions/5564737/threadpool-queueuserworkitem-with-function-argument\">ThreadPool.QueueUserWorkItem与函数参数

这篇关于ASP.NET真正的异步操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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