Visual Studio 2019 Forms application and Client Socket regarding thread's

David Bartel 1 Reputation point
2022-09-13T21:41:39.81+00:00

I have a Visual Studio 2019 Visual Basic forms application that communicates using a Client Socket with another PC (the other PC is the Socket server). The Client will periodically (once every 2 seconds) send a message to the Server and expect a reply in under 1 second.

Everything works fine until I power down the other PC (the server). The power down is abrupt and does not allow for any notification that its shutting down. It's like pulling the Ethernet Cable.

When that happens the main form (the only form) in my application appears to freeze up. I'm running the application in debug mode so to be more accurate Visual Studio itself does not freeze up, only the form. I can do a CTR-Break to stop and close the form.

I'm not sure whats happening with the form exactly but I'm wondering if perhaps its because the Client is operating in a blocking mode and perhaps (I don't know) the socket is operating on a different thread in the background. My theory is that the thread is waiting for something but not getting it and so it never returns to the forms application giving the appearance that the form is frozen.

Any help would be greatly appreciated.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,828 questions
Windows 10 Network
Windows 10 Network
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Network: A group of devices that communicate either wirelessly or via a physical connection.
2,272 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 43,931 Reputation points
    2022-09-19T08:02:18.677+00:00

    Hi David,

    Thank you for posting your query.

    To resolve your query kindly try running your VS in safe mode.

    Go to this link for your reference https://learn.microsoft.com/en-us/visualstudio/ide/reference/safemode-devenv-exe?view=vs-2019

    Do not hesitate to message us if you need further assistance.

    -------------------------------------------------------------------------------------------------------------------

    If the answer is helpful kindly click "Accept as Answer" and upvote it. Thanks.

    0 comments No comments

  2. David Bartel 1 Reputation point
    2022-09-22T16:16:02.903+00:00

    I'm a novice programmer and did not realize that in a Windows Forms application if my main form calls a Sub that effectively puts the program in an endless loop the form will appear to Freeze. This is basically what was happening in my program. I also later learned that I needed to use Socket send and Socket receive with blocking turned off so that if the server disconnected I would get an exception allowing me to continue program execution.

    All's well that ends well.

    0 comments No comments