[SOLVED] Custom Chat GUI Freezes After StreamReader Returns Null

I had a similar situation in the past where my reader would just return null/empty strings for seemingly unknown reasons.

As to why your UI freezes, this ismy best guess as to why it’s happening without knowing exactly how you’re handling things. You’re timer is calling your read function very frequently, and not just when your stream peaks. Unless you have safeguard checks against processing null data, it will halt and freeze the thread managing your UI since it’s trying to process null data very rapidly. A quick solution to get around this would be to put in checks if there are none, but a more permanent solution would be to make your read function async so the UI can remain responsive.

Instead of putting the read function in a timer, I’d recommend managing your own thread and using ReadLineAsync. It will require some more leg work but it is well worth it in my opinion. Unlike a timer, you have full control over your thread and instead of polling ever so often to read from the socket, it will only do work when your reader peaks or has data in it’s buffer. If you need an example, here’s how I implemented it in my library. I used a regular socket instead of a reader, but conceptually it’s the same.