I used following code to execute the SourceCreator
method without blocking UI.
string a =null;
private string SourceCreator()
{
string sum = textBox7.Text;
sum = sum.Replace(" ", "+");
string url = string.Format("https://www.aliexpress.com/wholesale?catId=0&initiative_id=SB_20220824221043&SearchText={0}&spm=a2g0o.productlist.1000002.0", sum);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
// richTextBox2.Text += sr.ReadToEnd();
a = sr.ReadToEnd();
sr.Close();
return a;
}
Here is button click event
private async void Timer4_Tick(object sender, EventArgs e)
{
Task<string> task1 = new Task<string>(SourceCreator);
task1.Start();
string p = await task1;
textBox10.Text = p;
}
I run this code, but this still blocking my UI of Windows form app. Could somebody tell me why?