From 25c34c0b881fc902c2ba63fa611bd482ed0ffd82 Mon Sep 17 00:00:00 2001 From: suntao Date: Wed, 18 Aug 2021 09:57:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=A0=E9=99=A4=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E5=AE=A2=E6=88=B7=E7=AB=AF=E6=97=B6=E4=BC=9A=E5=B4=A9?= =?UTF-8?q?=E6=BA=83=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ViewModels/MainWindowViewModel.cs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ViewModels/MainWindowViewModel.cs b/ViewModels/MainWindowViewModel.cs index a6d0c74..ae687f7 100644 --- a/ViewModels/MainWindowViewModel.cs +++ b/ViewModels/MainWindowViewModel.cs @@ -259,7 +259,7 @@ namespace OnlineUserPool.ViewModels private void SendMessage(Collection clients, List msgModels) { - if (!clients.Any()) + if (!clients.Any() || !msgModels.Any()) { return; } @@ -405,15 +405,22 @@ namespace OnlineUserPool.ViewModels } private void CientDisconnected(EndPoint point) - { - var client = Clients.FirstOrDefault(f => f.IPEndPoint.ToString() == point.ToString()); - if (client != null) + { + dispatcher.Invoke(() => { - dispatcher.Invoke(() => + try { - Clients.Remove(client); - }); - } + var client = Clients.FirstOrDefault(f => f.IPEndPoint.ToString() == point.ToString()); + if (client != null) + { + Clients.Remove(client); + } + } + catch(Exception ex) + { + Log.Information("在CientDisconnected触发以后,删除client时报错了,"+ ex.Message +", " + ex.StackTrace); + } + }); } }