public void CloseConnection() { users_ListBox.Items.Clear(); Chat_textBox.Clear(); sendMessage_textBox.Clear(); currentTime = new DateTime(); currentUser = ""; try { client.ConnectionFlag = false; client.Socket.Send(Encoding.UTF8.GetBytes(new Message(MessageType.UserDisconnect, DateTime.Now).Serialize())); //client.Socket.Shutdown(SocketShutdown.Both); //client.Socket.Close(); client.ListenThread.Abort(); } catch (NullReferenceException) { } catch (SocketException) { } this.Hide(); if (help != null) { help.Close(); } if (about != null) { about.Close(); } Program.cf.Show(); }
private void ServerErrorEventHandler(object handler, ServerErrorEventInfo e) { if (e.info != "Connection to server has been served") { return; } //я не понимаю что это но оно работает Action action = () => { sendMessage_textBox.Clear(); Chat_textBox.Clear(); // users.Items.Clear(); // client = new Client(); this.Hide(); }; if (InvokeRequired) { Invoke(action); } else { action(); } }
private void SendButton_Click(object sender, EventArgs e) { networkManager.threadSendQueue.Enqueue(Chat_textBox.Text); Chat_textBox.Clear(); }