void ConnectUDP(object sender, RoutedEventArgs e) { //Connect if (this.UDPclientWidow == null) { this.UDPclientWidow = new UDP.UDP_CLIENT_AUT_Window(); this.UDPclientWidow.DataReceived += this.DataReceived; this.UDPclientWidow.Show(); this.UDPButton.Content = "Close"; } //Close else { try { this.UDPclientWidow.Close(); this.CIPCButton.Content = "Connect"; } catch (Exception ex) { Console.Write(ex.Message); } } }