/// <summary> /// 添加用户到列表 /// </summary> /// <param name="userStr"></param> private void AddUserToTV(User user) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { users.Add(user); })); }
/// <summary> /// 移除用户 /// </summary> /// <param name="userName"></param> private void RemoveUserFromTV(User user) { Application.Current.Dispatcher.BeginInvoke(new Action(() => { for (int i = users.Count - 1; i >= 0; i--) { if (users[i].ID == user.ID) { users.RemoveAt(i); } } })); }
/// <summary> /// 刷新按钮 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRefresh_Click(object sender, RoutedEventArgs e) { loginUser = new User(); loginUser.Name = sysConfig.UserName; loginUser.HeadPath = sysConfig.UserHeadPath; loginUser.Autograph = sysConfig.UserAutograph; IPAddress clientIP = IPAddress.Parse(sysConfig.LocalIP); loginUser.IPAndPort = new IPEndPoint(clientIP, sysConfig.LocalPort); receiveUdpClient = new UdpClient(loginUser.IPAndPort); Thread receiveThread = new Thread(ReceiveMessage); receiveThread.Start(); sendUdpClient = new UdpClient(0); Thread sendThread = new Thread(SendMessage); UserDTO dto = new UserDTO { LoginState = UserLoginState.Login, LoginUser = loginUser }; sendThread.Start(JsonConvert.SerializeObject(dto, JsonHelper.GetIPJsonSettings())); this.btnRefresh.IsEnabled = false; this.btnLogout.IsEnabled = true; }