异步HttpWebRequest的从一个Web应用程序中没有等待 [英] Async HttpWebRequest with no wait from within a web application

查看:164
本文介绍了异步HttpWebRequest的从一个Web应用程序中没有等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Web应用程序(ASP.NET)我有一个使用的HttpWebRequest做出一个REST服务的调用并继续执行code块。现在它花费的时间比我想完成整个Web请求。问题是,什么REST服务返回的是没有用的。理想我想送一个异步Web请求到REST服务,然后不是等待响应。现在的问题是,我已经尝试过使用它

In my web application (ASP.NET) I have a block of code that uses HttpWebRequest to make a call to a REST service and continue execution. Right now it's taking longer than I would like to complete the full web request. The thing is that what the REST service returns isn't useful. Ideally I would like to send an Async web request to the REST service and then NOT wait for a response. The problem is that I've tried it out using

request.BeginGetResponse(New AsyncCallback(AddressOf myFunc), Nothing)

要启动一个异步请求,而不是没有等待(我会以为是一个异步请求的默认行为)后 BeginGetResponse 。

To start an async request and instead of NOT waiting (which I would assume would be the default behavior of an async request) it continuously executes the callback function before executing the next line of code after BeginGetResponse.

我怀疑当它是一个Web应用程序中的ASP.NET可以将其转换为一个同步请求。我带领相信这一点,因为有一个 IAsyncResult的结果传递到回调函数和对象时,我考察了 CompletedSynchronously 属性它始终设置为true。

I'm suspecting that ASP.NET may convert it to a sync request when it's within a web application. I'm led to believe this because there's a IAsyncResult result object that is passed into the callback function and when I examine its CompletedSynchronously property it's always set to true.

有谁知道是否有可能从一个ASP.NET Web应用程序中做一个异步HttpWebRequest的(没有等待),或者它总是转换为一个同步请求?

Does anyone know if it's possible to do an async HttpWebRequest (with no wait) from within an ASP.NET web application or is it always converted to a synchronous request?

推荐答案

你可能在看射后不理的格局。这里有一些联系。

you are probably looking at "fire and forget" pattern. Here are some links.

<一个href=\"http://weblogs.asp.net/albertpascual/archive/2009/05/14/fire-and-forget-class-for-asp-net.aspx\">http://weblogs.asp.net/albertpascual/archive/2009/05/14/fire-and-forget-class-for-asp-net.aspx

<一个href=\"http://haacked.com/archive/2009/01/09/asynchronous-fire-and-forget-with-lambdas.aspx\">http://haacked.com/archive/2009/01/09/asynchronous-fire-and-forget-with-lambdas.aspx

<一个href=\"http://www.eggheadcafe.com/articles/20060727.asp\">http://www.eggheadcafe.com/articles/20060727.asp

希望这有助于

这篇关于异步HttpWebRequest的从一个Web应用程序中没有等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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