ClientListWindow.xaml.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Shapes;
  13. using System.Collections;
  14. using AGV_WPF.Services;
  15. using System.Net.Sockets;
  16. namespace AGV_WPF.ExtraUI
  17. {
  18. /// <summary>
  19. /// ClientListWindow.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class ClientListWindow : Window
  22. {
  23. public ClientListWindow()
  24. {
  25. InitializeComponent();
  26. Server.ClientChanged += new EventHandler(Server_ClientChanged);
  27. }
  28. void Server_ClientChanged(object sender, EventArgs e)
  29. {
  30. this.Dispatcher.Invoke(new Action(delegate()
  31. {
  32. listBox1.Items.Clear();
  33. foreach (DictionaryEntry dic in Server.clientTable)
  34. {
  35. TcpClient client = dic.Key as TcpClient;
  36. if (client != null)
  37. listBox1.Items.Add(client.Client.RemoteEndPoint);
  38. }
  39. }));
  40. }
  41. private void Window_Loaded(object sender, RoutedEventArgs e)
  42. {
  43. this.Dispatcher.Invoke(new Action(delegate()
  44. {
  45. listBox1.Items.Clear();
  46. foreach (DictionaryEntry dic in Server.clientTable)
  47. {
  48. TcpClient client = dic.Key as TcpClient;
  49. if (client != null)
  50. listBox1.Items.Add(client.Client.RemoteEndPoint);
  51. }
  52. }));
  53. }
  54. }
  55. }