Reputation: 25701
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?
Upvotes: 0
Views: 428
Reputation: 6986
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.
Upvotes: 2