private void ProcessData(SocketData data) { switch (data.Command) { case (int)SocketCommand.NEW_GAME: this.Invoke((MethodInvoker)(() => { NewGame(); pnlChessBoard.Enabled = false; })); break; case (int)SocketCommand.QUIT: tmCooldown.Stop(); MessageBox.Show(this, "Opponent has exited!"); break; case (int)SocketCommand.SEND_POINT: this.Invoke((MethodInvoker)(() => { prcbTime.Value = 0; pnlChessBoard.Enabled = true; tmCooldown.Start(); OtherPlayerMark(data.Point); undoToolStripMenuItem.Enabled = true; })); break; case (int)SocketCommand.UNDO: Undo(); prcbTime.Value = 0; break; case (int)SocketCommand.TIME_OUT: MessageBox.Show(this, "Time out!"); break; case (int)SocketCommand.END_GAME: MessageBox.Show(this, "Game over!!"); break; default: break; } Listen(); }
private void Listen() { Thread listenThread = new Thread(() => { try { SocketData data = (SocketData)socket.Receive(); DataHandling(data); isPlaying = true; } catch (Exception e) { } }); listenThread.IsBackground = true; listenThread.Start(); }