Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed help adding a stop button --> HttpWebRequest
    text
    copied!<p>I have a program that has a button called "research" when that button is pressed it reads from an input text box that may say " how to * " </p> <p>It starts to pull auto suggestions from say google and the asterisk is replaced by each letter of the alphabet.</p> <p>My question is:</p> <p>I want a button to STOP the search. While it is in motion.</p> <p>What would be the best way to accomplish this?</p> <pre><code>private void btnResearch_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(txtResearch.Text.Trim())) { MessageBox.Show("Please enter a search query", "Oops", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } //Robin: Temporal fix to the multi asterisk if (txtResearch.Text.Trim().Count(s =&gt; s == '*') &gt; 1) { MessageBox.Show("Too many asterisk", "Oops", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (!ValidateLimitations()) { return; } ((LongTailBot.MainWindow)App.Current.MainWindow).PlaySound("button_double_click.wav"); this.chbSelAll.IsChecked = false; List&lt;KeywordItem&gt; keyList = new List&lt;KeywordItem&gt;(); this.dgrResearch.ItemsSource = null; List&lt;string&gt; seetKeywords = SetupSeetKeywords(txtResearch.Text.Trim().Replace(" ", "%20")); if (seetKeywords.Count() &lt; 1) return; foreach (string seetKey in seetKeywords) { this.txbResearch.Text = (seetKeywords.IndexOf(seetKey) + 1).ToString() + "/" + seetKeywords.Count() + " " + seetKey.Replace("%20", " "); Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { })); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.GetRequestUriString(seetKey)); request.Method = "GET"; request.UserAgent = @"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)"; WebResponse response = request.GetResponse(); if (((HttpWebResponse)response).StatusDescription.Trim().ToUpper() == "OK") { using (Stream dataStream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(dataStream)) { string responseFromServer = reader.ReadToEnd(); var keywordsFound = this.GetKeywordsFound(responseFromServer); foreach (var key in keywordsFound) { keyList.RemoveAll(k =&gt; k.Keyword == key); keyList.Add(new KeywordItem() { Checked = false, Keyword = key }); Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { })); } } } if (keyList.Count &gt; 0) { dgrResearch.ItemsSource = null; dgrResearch.ItemsSource = keyList; dgrResearch.ScrollIntoView(dgrResearch.Items[dgrResearch.Items.Count - 1]); } } response.Close(); } this.txbResearch.Text = this.dgrResearch.Items.Count.ToString() + " POPULAR PHRASES AVAILABLE!"; this.chbSelAll.IsChecked = dgrResearch.Items.Count &gt; 0? true : false; ((LongTailBot.MainWindow)App.Current.MainWindow).PlaySound("abstractbtn.wav"); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload