How to update UI from async routine without BeginInvoke or Invoke

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
I saw many code that they use BeginInvoke or invoke to update UI from another thread. is it possible to update UI from async function without BeginInvoke ?

one example given where BeginInvoke used to update UI.

private async void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
var count = 0;

await Task.Run(() =>
{
for (var i = 0; i <= 500; i++)
{
count = i;
BeginInvoke((Action)(() =>
{
label1.Text = i.ToString();

}));
Thread.Sleep(100);
}
});

label1.Text = @"Counter " + count;
button1.Enabled = true;
}

Continue reading...
 
Back
Top