question

DavidBartel-9670 avatar image
0 Votes"
DavidBartel-9670 asked DavidBartel-9670 answered

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

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-10-networkwindows-forms
· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@DavidBartel-9670, Welcome to Microsoft Q&A, based on your description, I almost understand your question. Therefore, how do you want to solve the freeze up? Just want to close the server or show some message box?

0 Votes 0 ·

I'd like to find a way to prevent the freeze up altogether. If there were some way to know that I've lost connection like a timeout or something and then I can check to see when the connection comes back.

0 Votes 0 ·

Did you determine which function hangs?


0 Votes 0 ·

I have a single function that writes to the stream and then reads from the stream. It appears to be freezing right after it writes to the stream.
I away from the application at the moment so I cant give you specifics but when I get a chance I'll be sure to answer in more detail.

0 Votes 0 ·
LimitlessTechnology-0326 avatar image
0 Votes"
LimitlessTechnology-0326 answered

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://docs.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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DavidBartel-9670 avatar image
0 Votes"
DavidBartel-9670 answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.