Hello,
Why my form does not respond on user actions with following code?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Net;
namespace SharpFive
{
public partial class Form1 : Form
{
public string m_text
{
get
{
return textBox1.Text;
}
set
{
textBox1.BeginInvoke(new Action(() => textBox1.Text = m_text + Environment.NewLine + value));
}
}
private static readonly List<string> urlArray = new List<string>
{
"http://www.google.com",
"http://www.bing.com",
"http://www.oreilly.com",
"http://www.simple-talk.com",
"http://www.microsoft.com",
"http://www.facebook.com",
"http://www.twitter.com",
"http://www.reddit.com",
"http://www.baidu.com",
"http://www.bbc.co.uk"
};
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
goingOn on = new goingOn(this);
foreach (string domain in urlArray)
{
on.Docompute(domain);
}
}
}
class goingOn
{
private readonly Form1 form;
public goingOn(Form1 form)
{
this.form = form;
}
private async Task<int> fire(string url)
{
WebClient webClient = new WebClient();
string page = await webClient.DownloadStringTaskAsync(url);
Thread.Sleep(1000);
return page.Length;
}
public async void Docompute(string urls)
{
int size = 0;
size = await fire(urls);
}
}
}