S
Sudip_inn
Guest
I am learning Task usage and async await usage. so i write a small program which will update my label value in loop. when i run application then application is getting freeze and label value change is not showing. so please guide me where i made the mistake. here is my code example.
private async void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
var count = 0;
await Task.Run(() =>
{
for (var i = 0; i <= 5000000; i++)
{
count = i;
BeginInvoke((Action)(() =>
{
label1.Text = i.ToString();
}));
}
});
label1.Text = @"Counter " + count;
button1.Enabled = true;
}
Continue reading...
private async void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
var count = 0;
await Task.Run(() =>
{
for (var i = 0; i <= 5000000; i++)
{
count = i;
BeginInvoke((Action)(() =>
{
label1.Text = i.ToString();
}));
}
});
label1.Text = @"Counter " + count;
button1.Enabled = true;
}
Continue reading...