Note that there are some explanatory texts on larger screens.

plurals
  1. POGUI not responding while fetching data
    text
    copied!<p>My application often fetch data from a webpage using WebRequest, but it isn't possible to click buttons etc while it's fetching. I've understood that I have to use threads/a backgroundworker, but I can't get it to work properly; it doesn't make the GUI more respondable. </p> <p>The code I want to apply some kind of threading on, so that it stops making my application unresponding:</p> <pre><code>public string SQLGet(string query) { string post = "q=" + query; WebRequest request = WebRequest.Create("http://test.com"); request.Timeout = 20000; request.Method = "POST"; byte[] bytes = Encoding.UTF8.GetBytes(post); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = bytes.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); WebResponse response = request.GetResponse(); requestStream = response.GetResponseStream(); StreamReader reader = new StreamReader(requestStream); string ret = reader.ReadToEnd(); reader.Close(); requestStream.Close(); response.Close(); return ret; } </code></pre> <hr> <p>Edit: Thank you, lc, I had tried something pretty similar to that. But my problem with using the backgroundworker like that is; how do I get the queryResult back to the function which called (in my case SQLGet, and in your case) StartQuery?</p> <p>In my example, the returned string is going to be used as a local variable in the void the string is called inside. </p> <p>And there may be many queries at the same time, so I don't want to risk assigning it to a global variable. </p>
 

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