private void BeginTryToConnectParticipant(Participant participant, string nickname) { participant.BeginSend(new Message(nickname), () => { participant.BeginReceive(OnMessage, exception => { throw exception; }); }, OnError); }
private static void OnReceiveMessage(Message message) { participant.Nickname = message.ToString(); if (room.Join(participant)) { Console.WriteLine("--" + participant.Nickname + "--"); participant.BeginSend(new Message("Yes"), () => { participant.BeginSend(new Message(room.GetParticipantsNicknames()), () => { BroadcastMessage(participant); }, OnError); }, OnError); } else { participant.BeginSend(new Message("No"), () => { TryToReceive(participant); }, OnError); } }
private void BeginWrite(Participant participant, string text) { try { if (text == string.Empty) { throw new EmptyMessageException(); } Message message = new Message(text); participant.BeginSend(message, () => { Dispatcher.Invoke(() => messageBox.Text = string.Empty); }, OnBeginWriteError); } catch (EmptyMessageException exception) { OnBeginWriteError(exception); } }