private void btnStart_Click(object sender, EventArgs e) { try { String ip = this.txtIpAddress.Text.Trim(); ushort port = ushort.Parse(this.txtPort.Text.Trim()); // 写在这个位置是上面可能会异常 SetAppState(AppState.Starting); AddMsg(string.Format("$Client Starting ... -> ({0}:{1})", ip, port)); if (client.Connect(ip, port, this.cbxAsyncConn.Checked)) { if (cbxAsyncConn.Checked == false) { SetAppState(AppState.Started); } } else { SetAppState(AppState.Stoped); throw new Exception(string.Format("$Client Start Error -> {0}({1})", client.ErrorMessage, client.ErrorCode)); } } catch (Exception ex) { AddMsg(ex.Message); } }
public HandleResult Connect() { string ip = ConfigurationManager.AppSettings.Get("ip"); string portTemp = ConfigurationManager.AppSettings.Get("port"); ushort port = ushort.Parse(portTemp.Trim()); bool d = client.Connect(ip, port, true); //appState = AppState.Started; //SetControlState(); return(HandleResult.Ok); }