private async void Button_Click(object sender, RoutedEventArgs e) { try { //gets the selected method from the combobox string method = (string)comboBox1.SelectedItem; //gets the data from the text box string data = textBox1.Text; //calls the request method Task <string> tsResponse = TCPClientConConfig.SendRequest(client, method, data); //give client text listBox1.Items.Add("Sent request, waiting for response"); //waits for response await tsResponse; //converts the response into decimal decimal dResponse = decimal.Parse(tsResponse.Result); listBox1.Items.Add("Received response: " + dResponse.ToString("F2")); } catch (FormatException ex) { listBox1.Items.Add(ex.Message); } catch (Exception ex) { MessageBox.Show(ex.Message); this.Close(); App.Current.Shutdown(); } }
private async void Window_Loaded(object sender, RoutedEventArgs e) { TCPClientConConfig clientConConfig = new TCPClientConConfig(); client = await clientConConfig.Connect(); }