Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Difference Between BeginGetResponse and GetResponse

Difference Between BeginGetResponse and GetResponse

Scheduled Pinned Locked Moved C#
csharpjavascriptcomhelptutorial
7 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    baranils
    wrote on last edited by
    #1

    Hello Does anyone have already experienced the BeginGetResponse illutrated in the Microsoft example ? http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.begingetresponse.aspx[^] My need will be to make an hrttprequest in asynchronous mode. To not let the user wait for a response that can be processed in backround. First I was thinking to use a BackroundWorker, then I see that begingetresponse example But it react exacly as the BeginResponse : when I step over it wait a few seconds to get the response. So maybe I misunderstand something but I don't see any advantage of this method ?? Thank for your help

    Richard Andrew x64R T 2 Replies Last reply
    0
    • B baranils

      Hello Does anyone have already experienced the BeginGetResponse illutrated in the Microsoft example ? http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.begingetresponse.aspx[^] My need will be to make an hrttprequest in asynchronous mode. To not let the user wait for a response that can be processed in backround. First I was thinking to use a BackroundWorker, then I see that begingetresponse example But it react exacly as the BeginResponse : when I step over it wait a few seconds to get the response. So maybe I misunderstand something but I don't see any advantage of this method ?? Thank for your help

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      When you run it, is it timing out? Or is it receiving a response?

      The difficult we do right away... ...the impossible takes slightly longer.

      1 Reply Last reply
      0
      • B baranils

        Hello Does anyone have already experienced the BeginGetResponse illutrated in the Microsoft example ? http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.begingetresponse.aspx[^] My need will be to make an hrttprequest in asynchronous mode. To not let the user wait for a response that can be processed in backround. First I was thinking to use a BackroundWorker, then I see that begingetresponse example But it react exacly as the BeginResponse : when I step over it wait a few seconds to get the response. So maybe I misunderstand something but I don't see any advantage of this method ?? Thank for your help

        T Offline
        T Offline
        Trak4Net
        wrote on last edited by
        #3

        BeginGetResponse will execute the method in the AsyncCallBack asynchronously. If you do like in the MSDN example then it will wait for that asynchronous operation to finish this is the code that will cause it to wait and also implements a timeout method so if the asynchronous operation takes to long it will end the asynchronous operation.

        // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted
        ThreadPool.RegisterWaitForSingleObject (result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), myHttpWebRequest, DefaultTimeout, true);

          // The response came in the allowed time. The work processing will happen in the
          // callback function.
          allDone.WaitOne();
        
        B 1 Reply Last reply
        0
        • T Trak4Net

          BeginGetResponse will execute the method in the AsyncCallBack asynchronously. If you do like in the MSDN example then it will wait for that asynchronous operation to finish this is the code that will cause it to wait and also implements a timeout method so if the asynchronous operation takes to long it will end the asynchronous operation.

          // this line implements the timeout, if there is a timeout, the callback fires and the request becomes aborted
          ThreadPool.RegisterWaitForSingleObject (result.AsyncWaitHandle, new WaitOrTimerCallback(TimeoutCallback), myHttpWebRequest, DefaultTimeout, true);

            // The response came in the allowed time. The work processing will happen in the
            // callback function.
            allDone.WaitOne();
          
          B Offline
          B Offline
          baranils
          wrote on last edited by
          #4

          Thank for the answer But it seems that the BeginGetResponse itself takes long to come back // Start the asynchronous request. IAsyncResult result= (IAsyncResult) myHttpWebRequest.BeginGetResponse(new AsyncCallback(RespCallback),myRequestState); I test it a few times yesterday But today I try again and now it return immediately ! Even if I cut the network connexion ! I probably miss something !:confused: Some told me that I have to wrap this code example in a dedicated thread ! But if so I dond see the advantage of using the BeginGetResponse

          T 1 Reply Last reply
          0
          • B baranils

            Thank for the answer But it seems that the BeginGetResponse itself takes long to come back // Start the asynchronous request. IAsyncResult result= (IAsyncResult) myHttpWebRequest.BeginGetResponse(new AsyncCallback(RespCallback),myRequestState); I test it a few times yesterday But today I try again and now it return immediately ! Even if I cut the network connexion ! I probably miss something !:confused: Some told me that I have to wrap this code example in a dedicated thread ! But if so I dond see the advantage of using the BeginGetResponse

            T Offline
            T Offline
            Trak4Net
            wrote on last edited by
            #5

            I'm thinking you must have missed something initially, BeginGetResponse should return immedialtely. The only reason I would see to run that in a dedicated thread is if you want to worry about a timeout or want to ensure the asynchronous method completes like the example, as the method will block waiting for the ManualResetEvent to be set. Using the ManualResetEvent is for situations where you can't process the next step until that process has completed.

            B 1 Reply Last reply
            0
            • T Trak4Net

              I'm thinking you must have missed something initially, BeginGetResponse should return immedialtely. The only reason I would see to run that in a dedicated thread is if you want to worry about a timeout or want to ensure the asynchronous method completes like the example, as the method will block waiting for the ManualResetEvent to be set. Using the ManualResetEvent is for situations where you can't process the next step until that process has completed.

              B Offline
              B Offline
              baranils
              wrote on last edited by
              #6

              Thank you Trak4Net Ok ... maybe I was too tired yesterday I will try again tonight But indeed I'm expecting that BeginGetResponse return immediately whatever the connexion state !

              T 1 Reply Last reply
              0
              • B baranils

                Thank you Trak4Net Ok ... maybe I was too tired yesterday I will try again tonight But indeed I'm expecting that BeginGetResponse return immediately whatever the connexion state !

                T Offline
                T Offline
                Trak4Net
                wrote on last edited by
                #7

                Some more investigation turns out this is a known issue. Apparently it blocks during the name resolution so does not return immediately as you would think. Sorry, I should have looked into it a little more before replying. http://social.msdn.microsoft.com/forums/en-US/netfxnetcom/thread/2cb74a7e-6e8f-4d05-b86a-2401df5d2ed3/[^]

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups