private void MessageCallBack(IAsyncResult aResult) { try { int size = sck.EndReceiveFrom(aResult, ref epRemote); if (size > 0) { byte[] receivedData = new byte[1464]; receivedData = (byte[])aResult.AsyncState; ASCIIEncoding eEncoding = new ASCIIEncoding(); string receivedMessage = eEncoding.GetString(receivedData); System.Windows.Application.Current.Dispatcher.Invoke( (Action)(() => { CallModel.Chat.Insert(0, CallModel.FriendLogin + ": " + clearMessage(receivedMessage)); callWindow.scrollToButtom(); } )); if (clearMessage(receivedMessage) == "%SYSTEM%YESIWAIT" && CallModel.CallState == "select") { System.Windows.Application.Current.Dispatcher.Invoke( (Action)(() => { callWindow.ActiveButton(); } )); } if (clearMessage(receivedMessage) == "%SYSTEM%INOTRECEIVECALL" && CallModel.CallState == "create") { System.Windows.Application.Current.Dispatcher.Invoke( (Action)(() => { MessageBox.Show(CallModel.FriendLogin + " niechce odebrać połączenia."); CloseWindow(); } )); } if (clearMessage(receivedMessage) == "%SYSTEM%IRESIGNEDCALL" && CallModel.CallState == "select") { System.Windows.Application.Current.Dispatcher.Invoke( (Action)(() => { MessageBox.Show(CallModel.FriendLogin + " zrezygnował z połączenia."); CloseWindow(); } )); } if (clearMessage(receivedMessage) == "%SYSTEM%STARTCALL" && CallModel.CallState == "create") { System.Windows.Application.Current.Dispatcher.Invoke( (Action)(() => { StartCall(); } )); } if (clearMessage(receivedMessage) == "%SYSTEM%IENDCALL" && CallModel.CallState == "call") { System.Windows.Application.Current.Dispatcher.Invoke( (Action)(() => { MessageBox.Show(CallModel.FriendLogin + " zakończył połączenie."); endCall(); CloseWindow(); } )); } } byte[] buffer = new byte[1500]; sck.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref epRemote, new AsyncCallback(MessageCallBack), buffer); } catch (Exception exp) { //MessageBox.Show(exp.ToString()); } }