开发者

Page Lifecycle and Asynchronous Requests in C# asp.net web forms

开发者 https://www.devze.com 2023-04-13 01:50 出处:网络
If I send an HttpWebRequest 开发者_开发问答and send it out with BeginGetResponse with a callback, my callback never gets hit. THe page finishes before the response is given.

If I send an HttpWebRequest 开发者_开发问答and send it out with BeginGetResponse with a callback, my callback never gets hit. THe page finishes before the response is given.

How do I grab the response?

I have tried setting a timer:

  ThreadPool.RegisterWaitForSingleObject(result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), null, DefaultTimeout, true);

but again if DefaultTimeout (in milliseonds) is set to 1 millisecond, it reaches the callback. But if it is set to 30 seconds, then the callback never gets fired.

How do I access the request/result again?


If you want to wait for the web request to complete before allowing your code to continue executing, you'll need to use the synchronous GetResponse method instead of the asynchronous BeginGetResponse method. This will block the current thread until the request completes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号