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. Asynchronous Question

Asynchronous Question

Scheduled Pinned Locked Moved C#
questioncsharpjavacomtools
7 Posts 4 Posters 0 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.
  • P Offline
    P Offline
    Programm3r
    wrote on last edited by
    #1

    Hi all, Some background information: I have a method A that calls another method B. In method B an asynchronous TCP/IP read occurs: this.tcpClient.GetStream().BeginRead(byteReadBuffer, 0, byteReadBuffer.Length, new AsyncCallback(ProcessReadBuffer), tcpClient.GetStream()); on result method ProcessReadBuffer So my question: How can I wait for the asynchronous ProcessReadBuffer method to complete in method B. Reason being that I require some results from ProcessReadBuffer method in method A? Many thanks in advance. Kind regards,

    The only programmers that are better C# programmers, are those who look like this -> :bob:

    :java: Programm3r My Blog: ^_^

    R A A 3 Replies Last reply
    0
    • P Programm3r

      Hi all, Some background information: I have a method A that calls another method B. In method B an asynchronous TCP/IP read occurs: this.tcpClient.GetStream().BeginRead(byteReadBuffer, 0, byteReadBuffer.Length, new AsyncCallback(ProcessReadBuffer), tcpClient.GetStream()); on result method ProcessReadBuffer So my question: How can I wait for the asynchronous ProcessReadBuffer method to complete in method B. Reason being that I require some results from ProcessReadBuffer method in method A? Many thanks in advance. Kind regards,

      The only programmers that are better C# programmers, are those who look like this -> :bob:

      :java: Programm3r My Blog: ^_^

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      Why not just call it synchronously then?

      Regards, Rob Philpott.

      P 1 Reply Last reply
      0
      • R Rob Philpott

        Why not just call it synchronously then?

        Regards, Rob Philpott.

        P Offline
        P Offline
        Programm3r
        wrote on last edited by
        #3

        Good point ... :sigh: That's that I did at the end of the day, but was curious how to make it happen :confused:

        The only programmers that are better C# programmers, are those who look like this -> :bob:

        :java: Programm3r My Blog: ^_^

        1 Reply Last reply
        0
        • P Programm3r

          Hi all, Some background information: I have a method A that calls another method B. In method B an asynchronous TCP/IP read occurs: this.tcpClient.GetStream().BeginRead(byteReadBuffer, 0, byteReadBuffer.Length, new AsyncCallback(ProcessReadBuffer), tcpClient.GetStream()); on result method ProcessReadBuffer So my question: How can I wait for the asynchronous ProcessReadBuffer method to complete in method B. Reason being that I require some results from ProcessReadBuffer method in method A? Many thanks in advance. Kind regards,

          The only programmers that are better C# programmers, are those who look like this -> :bob:

          :java: Programm3r My Blog: ^_^

          A Offline
          A Offline
          Abhinav S
          wrote on last edited by
          #4

          Try storing the result in an IAsyncResult variable and then call AsyncWaitHandle.WaitOne() on that object.

          P 1 Reply Last reply
          0
          • A Abhinav S

            Try storing the result in an IAsyncResult variable and then call AsyncWaitHandle.WaitOne() on that object.

            P Offline
            P Offline
            Programm3r
            wrote on last edited by
            #5

            Hi, Thanks for the response. I did try doing that, but I noticed that the WaitOne() returns immediately with a true result and only then after it goes into the method. Kind regards,

            The only programmers that are better C# programmers, are those who look like this -> :bob:

            :java: Programm3r My Blog: ^_^

            A 1 Reply Last reply
            0
            • P Programm3r

              Hi all, Some background information: I have a method A that calls another method B. In method B an asynchronous TCP/IP read occurs: this.tcpClient.GetStream().BeginRead(byteReadBuffer, 0, byteReadBuffer.Length, new AsyncCallback(ProcessReadBuffer), tcpClient.GetStream()); on result method ProcessReadBuffer So my question: How can I wait for the asynchronous ProcessReadBuffer method to complete in method B. Reason being that I require some results from ProcessReadBuffer method in method A? Many thanks in advance. Kind regards,

              The only programmers that are better C# programmers, are those who look like this -> :bob:

              :java: Programm3r My Blog: ^_^

              A Offline
              A Offline
              Alan N
              wrote on last edited by
              #6

              Hi, BeginRead does not have to specify a callback method and you then call EndRead when the result of the async operation is required. EndRead will block until the result is available. http://msdn.microsoft.com/en-us/library/ms228967.aspx[^] Alan.

              1 Reply Last reply
              0
              • P Programm3r

                Hi, Thanks for the response. I did try doing that, but I noticed that the WaitOne() returns immediately with a true result and only then after it goes into the method. Kind regards,

                The only programmers that are better C# programmers, are those who look like this -> :bob:

                :java: Programm3r My Blog: ^_^

                A Offline
                A Offline
                Abhinav S
                wrote on last edited by
                #7

                Strange - this is how I used it - ar = u.BeginInvoke(param, new AsyncCallback(Complete), "state"); ar.AsyncWaitHandle.WaitOne(); u was the my delegate and param was the parameter I passed into that method that my delegate invoked.

                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