private async void Button_Click(object sender, RoutedEventArgs e) { try { Socket Server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); Server.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 80)); Server.Listen(2); Socket Client; await Task.Run(() => { Client = Server.Accept(); TextBox1.Text = "Hello"; }); } catch (Exception ex) { Console.WriteLine("Exception: " + ex); } }