private void timer_10ms_Tick(object sender, EventArgs e) { string err = ""; if (bConnected) { string s; if (client.Receive(out s, out err)) { if (s != "") { textBox_Receive.Text += s; } } else { // error handling, client socket seems to be disconnected client.Disconnect(out err); textBox_Receive.Text += err + "\r\n"; } textBox_Receive.SelectionStart = textBox_Receive.TextLength; textBox_Receive.ScrollToCaret(); } // Check every 1 second (1000 ms) if the socket is still connected if (nTimer_10ms % 100 == 0) { if (bConnected) { if (!client.IsStillConnected()) { bConnected = false; SetGUIstate(bConnected); textBox_Receive.Text += "DEBUG > " + "Disconnected from server.\r\n"; textBox_Receive.SelectionStart = textBox_Receive.TextLength; textBox_Receive.ScrollToCaret(); } } } nTimer_10ms++; }