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. Socket.Receive method. It blocks the UI

Socket.Receive method. It blocks the UI

Scheduled Pinned Locked Moved C#
designhelpquestion
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.
  • D Offline
    D Offline
    Diego F
    wrote on last edited by
    #1

    Hello. I'm using the socket class in an application and I use socket.receive to wait for data. The problem is that the interface gets locked while the receive method is executing. I want to see the interface so the user knows what's happening at any time. Is that possible?

    Regards, Diego F.

    N 1 Reply Last reply
    0
    • D Diego F

      Hello. I'm using the socket class in an application and I use socket.receive to wait for data. The problem is that the interface gets locked while the receive method is executing. I want to see the interface so the user knows what's happening at any time. Is that possible?

      Regards, Diego F.

      N Offline
      N Offline
      Niiiissssshhhhhuuuuu
      wrote on last edited by
      #2

      Hello, Put that socket code in diffrent thread..or it will block th UI until it receives the connection.. Regards :rose:, Nishu

      D 1 Reply Last reply
      0
      • N Niiiissssshhhhhuuuuu

        Hello, Put that socket code in diffrent thread..or it will block th UI until it receives the connection.. Regards :rose:, Nishu

        D Offline
        D Offline
        Diego F
        wrote on last edited by
        #3

        Thank you!

        Regards, Diego F.

        D C 2 Replies Last reply
        0
        • D Diego F

          Thank you!

          Regards, Diego F.

          D Offline
          D Offline
          Diego F
          wrote on last edited by
          #4

          I found a problem with that. Now, I can't access the UI controls, as they are in other thread. I get an execution exception. How can I solve that?

          Regards, Diego F.

          C J 2 Replies Last reply
          0
          • D Diego F

            Thank you!

            Regards, Diego F.

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            Youc can also use BeginReceive and EndReceive to achieve the same. This moves the thread handling to the Socket class. If you are doing lots of operations then you might want to do the thread handling yourself.


            Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

            1 Reply Last reply
            0
            • D Diego F

              I found a problem with that. Now, I can't access the UI controls, as they are in other thread. I get an execution exception. How can I solve that?

              Regards, Diego F.

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              You can use the Invoke method on the control or form to run the method you are calling on the correct thread.


              Upcoming events: * Glasgow: SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

              1 Reply Last reply
              0
              • D Diego F

                I found a problem with that. Now, I can't access the UI controls, as they are in other thread. I get an execution exception. How can I solve that?

                Regards, Diego F.

                J Offline
                J Offline
                jayart
                wrote on last edited by
                #7

                You might be getting the cross-thread exception. try this // UI class functions public void UpdateMenus() { if (this.InvokeRequired) { this.Invoke(new UpdateMenusDelegate(UpdateMenus), new object[] { sender, e }); return; } // continue with your code }

                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