0

Hello stackoverflow..

Currently i'm working on a game bot which connects to game server using Socket and it receives data from the game server.
However Tab_1 got game connection setting ,Tab_2 holds a textbox which is game chat. When i debug my app and connect to server directly without selecting Tab_2 and the bot receives chat data it append it to textbox which is at Tab_2. now the problem , When i select Tab_2 the whole program freeze for about 1 minute and of course my socket disconnected also i can't fine the textbox!!

Thanks in advance.

Muhab
  • 367
  • 1
  • 2
  • 13
  • I don't really understand your situation, but I'd recommend that you run the socket connection to the game server on a different thread than the UI thread. Then you do have the complications of cross-thread communication between the UI thread and the socket thread, but still it will be a better design and less likely to cause problems once you get it working. – RenniePet Dec 09 '14 at 22:14
  • That's what i'm really doing, socket connection got it's own thread even it's received data handles on another class and from that data class i append text into textbox using "static Form1 MainWindow;". – Muhab Dec 09 '14 at 23:30
  • To send data from your socket thread to your UI thread you need to use control.Invoke() or control.BeginInvoke() to dispatch a method in your Form class. – RenniePet Dec 09 '14 at 23:53
  • hmm can u explain more how can i do that using textbox.appendtext(message)? Btw i have tried to write a method in UI thread to append texts to textbox and just call this method from Data thread and that's not working too. – Muhab Dec 10 '14 at 08:31
  • There are several ways of doing this. http://stackoverflow.com/questions/661561/how-to-update-the-gui-from-another-thread-in-c and http://stackoverflow.com/questions/12131453/update-winform-controls-from-another-thread-and-class and http://stackoverflow.com/questions/11211533/update-a-control-in-ui-with-running-background-thread-in-winforms are the top three Google hits I found. – RenniePet Dec 10 '14 at 12:20

0 Answers0