private void btnStart_Click(object sender, RoutedEventArgs e) { btnStart.IsEnabled = false; btnStop.IsEnabled = true; string ip = this.cbbIP.SelectedValue.ToString(); //MessageBox.Show(ip+":"+txtPort.Text+"已开始监听"); int p = int.Parse(txtPort.Text); helper = new TCPHelper(IPAddress.Parse(ip), p); helper.ExHandler += ShowMsg; helper.StartListen(p); ShowMsg(null, string.Format("{0}:{1}-->监听已开始", helper.IP, helper.port)); helper.AddTcpClientHandler += CreateClientTask; Task.Run(() => helper.ListenClient()); }