private void CheckServer() { THcheckServer = new Thread(() => { while (true) { try { uint ServerNetID = 0; WClient wc = new WClient("127.0.0.1", 5999); byte[] ret = wc.SendReceive(new byte[] { 0 }); // get netid proc wc.Close(); BinaryReader rdr = new BinaryReader(new MemoryStream(ret)); rdr.ReadByte(); ServerNetID = rdr.ReadUInt32(); Statik.LastServerNetID = ServerNetID; Dispatcher.Invoke(() => { btnSendServer.IsEnabled = true; }); } catch (Exception) { Dispatcher.Invoke(() => { btnSendServer.IsEnabled = false; }); } Thread.Sleep(1000); } }); THcheckServer.Start(); }
private void btnSendServer_Click(object sender, RoutedEventArgs e) { try { var bytes = this.pro.getBytes(); byte[] tmp = new byte[bytes.Length + 1]; tmp[0] = 1; Array.Copy(bytes, 0, tmp, 1, bytes.Length); WClient wc = new WClient("127.0.0.1", 5999); wc.Send(tmp); wc.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }