// Calculate button event handler private void buttonCalculate_Click(object sender, EventArgs e) { // Connect to server if not already if (remoteObject == null) { // Opening channel TcpChannel channel = new TcpChannel(); // Registering channel ChannelServices.RegisterChannel(channel, true); // Building connection string string connectionString = string.Format(connectFormatString, defaultPort, defaultClassName); // Getting reference for instance of library remoteObject = (Lib)Activator.GetObject(typeof(Lib), connectionString); } double argument = 0.0; double result = 0.0; // Trying to parse number in text field, if not success then display error if (!double.TryParse(textBoxArgument.Text, out argument)) { MessageBox.Show("Enter DOUBLE number in correct format. \nWARNING: separator in ',' symbol", "Error"); return; } else { // Call server object for cos calculating result = remoteObject.Calculate(argument); // Display answer labelAnswer.Text = string.Format("Answer: {0}", result); } }
private void buttonCalculate_Click(object sender, EventArgs e) { if (remoteObject == null) { // Opening channel TcpChannel channel = new TcpChannel(); // Registering channel ChannelServices.RegisterChannel(channel, true); // Getting reference for instance of library remoteObject = (Lib)Activator.GetObject(typeof(Lib), "tcp://localhost:11114/equ"); } string result; double a = 0; double b = 0; double c = 0; bool parsingOk = double.TryParse(textBox0.Text, out a); parsingOk &= double.TryParse(textBox1.Text, out b); parsingOk &= double.TryParse(textBox2.Text, out c); if (parsingOk == false) { MessageBox.Show("One or more args in wrong format. Check flields. Separator ','", "Error", MessageBoxButtons.OK); return; } result = remoteObject.Calculate(a, b, c); labelAnswer.Text = result; }