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. the Form stop to respond

the Form stop to respond

Scheduled Pinned Locked Moved C#
csharpc++testingdebuggingbeta-testing
5 Posts 3 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.
  • B Offline
    B Offline
    bouli
    wrote on last edited by
    #1

    Hi gurus, I am currently testing the TcpListener and TcpClient classes from System.Net.Socket to try to send data from a pc to another. I have inserted a static control that displays the status of the connection. I do the following code: ... Int32 port=Int32.Parse(txtPort.Text); NetworkStream stream=null; Socket socket=null; m_server=new TcpListener(IPAddress.Any, port); m_server.Start(); while (true) { lblStatus.Text="Waiting for a connection..."; Debug.WriteLine(lblStatus.Text); socket=m_server.AcceptSocket(); ... When I check the output I can see the message "Waiting for connection..." (that's what I wanted) but the form seems to be completely frozen once the call to socket=m_server.AcceptSocket() is done. Should I write this function in a separate thread? Then the interface could answer to the OnPaint events like in C++? If I have to write a thread for what I'm doing, where I can I get a sample code for it? Thanks for the help. Best regards. There is no spoon.

    H W 2 Replies Last reply
    0
    • B bouli

      Hi gurus, I am currently testing the TcpListener and TcpClient classes from System.Net.Socket to try to send data from a pc to another. I have inserted a static control that displays the status of the connection. I do the following code: ... Int32 port=Int32.Parse(txtPort.Text); NetworkStream stream=null; Socket socket=null; m_server=new TcpListener(IPAddress.Any, port); m_server.Start(); while (true) { lblStatus.Text="Waiting for a connection..."; Debug.WriteLine(lblStatus.Text); socket=m_server.AcceptSocket(); ... When I check the output I can see the message "Waiting for connection..." (that's what I wanted) but the form seems to be completely frozen once the call to socket=m_server.AcceptSocket() is done. Should I write this function in a separate thread? Then the interface could answer to the OnPaint events like in C++? If I have to write a thread for what I'm doing, where I can I get a sample code for it? Thanks for the help. Best regards. There is no spoon.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      There's plenty of examples of threading socket connections here on CodeProject. When you get and set properties on a control or form, however, you must invoke the call so that it executes on the main UI thread otherwise you'll run into problems. See Control.Invoke and Control.InvokeRequired for more information and an example of how to use them.

      Microsoft MVP, Visual C# My Articles

      B 1 Reply Last reply
      0
      • B bouli

        Hi gurus, I am currently testing the TcpListener and TcpClient classes from System.Net.Socket to try to send data from a pc to another. I have inserted a static control that displays the status of the connection. I do the following code: ... Int32 port=Int32.Parse(txtPort.Text); NetworkStream stream=null; Socket socket=null; m_server=new TcpListener(IPAddress.Any, port); m_server.Start(); while (true) { lblStatus.Text="Waiting for a connection..."; Debug.WriteLine(lblStatus.Text); socket=m_server.AcceptSocket(); ... When I check the output I can see the message "Waiting for connection..." (that's what I wanted) but the form seems to be completely frozen once the call to socket=m_server.AcceptSocket() is done. Should I write this function in a separate thread? Then the interface could answer to the OnPaint events like in C++? If I have to write a thread for what I'm doing, where I can I get a sample code for it? Thanks for the help. Best regards. There is no spoon.

        W Offline
        W Offline
        wibblewibblewibble
        wrote on last edited by
        #3

        I had the same problem and used seperate threads for waiting on a connection, and sending and receiving data. This frees up the main thread so the UI doesn't appear to stop responding. This link - http://staff.develop.com/woodring/dotnet/#socketsamp[^] - posted in reply to an article gives a good example, which got me going. Barry

        B 1 Reply Last reply
        0
        • W wibblewibblewibble

          I had the same problem and used seperate threads for waiting on a connection, and sending and receiving data. This frees up the main thread so the UI doesn't appear to stop responding. This link - http://staff.develop.com/woodring/dotnet/#socketsamp[^] - posted in reply to an article gives a good example, which got me going. Barry

          B Offline
          B Offline
          bouli
          wrote on last edited by
          #4

          ok, thanks. I'm going to explore this way.;P There is no spoon.

          1 Reply Last reply
          0
          • H Heath Stewart

            There's plenty of examples of threading socket connections here on CodeProject. When you get and set properties on a control or form, however, you must invoke the call so that it executes on the main UI thread otherwise you'll run into problems. See Control.Invoke and Control.InvokeRequired for more information and an example of how to use them.

            Microsoft MVP, Visual C# My Articles

            B Offline
            B Offline
            bouli
            wrote on last edited by
            #5

            ok, I'm going to check this way :) There is no spoon.

            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