void DoGetPatronInfo() { string strError = ""; EnableControls(false); try { CancellationToken cancel_token = new CancellationToken(); string id = Guid.NewGuid().ToString(); SearchRequest request = new SearchRequest(id, "getPatronInfo", "", this.textBox_getReaderInfo_queryWord.Text, "", "", this.textBox_getReaderInfo_formatList.Text, 1); try { Task <MessageConnection> task = this._channels.GetConnectionAsync( this.textBox_config_messageServerUrl.Text, this.textBox_getReaderInfo_remoteUserName.Text); SearchResult result = task.ContinueWith <SearchResult>((antecendent) => { if (antecendent.IsFaulted == true) { throw antecendent.Exception; } MessageConnection connection = task.Result; return(connection.SearchAsync( this.textBox_getReaderInfo_remoteUserName.Text, request, new TimeSpan(0, 1, 0), cancel_token).Result); }).Result; this.Invoke(new Action(() => { if (result.ResultCount == 0) { this.textBox_getReaderInfo_results.Text = "没有找到"; } else { this.textBox_getReaderInfo_results.Text = ToString(result); } })); } catch (AggregateException ex) { strError = MessageConnection.GetExceptionText(ex); goto ERROR1; } catch (Exception ex) { strError = ex.Message; goto ERROR1; } return; } finally { EnableControls(true); } ERROR1: this.Invoke((Action)(() => MessageBox.Show(this, strError))); }
async void DoGetInfo() { string strError = ""; if (string.IsNullOrEmpty(this.comboBox_getInfo_method.Text) == true) { strError = "尚未指定方法"; goto ERROR1; } EnableControls(false); try { CancellationToken cancel_token = new CancellationToken(); string id = Guid.NewGuid().ToString(); SearchRequest request = new SearchRequest(id, this.comboBox_getInfo_method.Text, "", this.textBox_getInfo_queryWord.Text, "", "", "", this.textBox_getInfo_formatList.Text, 1, 0, -1); try { MessageConnection connection = await this._channels.GetConnectionAsync( this.textBox_config_messageServerUrl.Text, this.textBox_getInfo_remoteUserName.Text); SearchResult result = await connection.SearchAsync( this.textBox_getInfo_remoteUserName.Text, request, new TimeSpan(0, 1, 0), cancel_token); this.Invoke(new Action(() => { if (result.ResultCount == 0) { SetTextString(this.webBrowser1, "没有找到"); } else { SetTextString(this.webBrowser1, ToString(result)); } })); } catch (AggregateException ex) { strError = MessageConnection.GetExceptionText(ex); goto ERROR1; } catch (Exception ex) { strError = ex.Message; goto ERROR1; } return; } finally { EnableControls(true); } ERROR1: this.Invoke((Action)(() => MessageBox.Show(this, strError))); }