Performance Tips for Asynchronous Development in C#: Listing 1.

Revised Click event handler.

private void button1_Click(object sender, EventArgs e)
{
  UpdateTime();
}

private async void UpdateTime()
{
  button1.Enabled = false;
  for (var x = 0; x < 15; x++)
  {
    this.Text = DateTime.Now.ToString("HH:mm:ss");
    await TaskEx.Delay(1000);
  }
  button1.Enabled = true;
}

About the Author

Patrick Steele is a senior .NET developer with Billhighway in Troy, Mich. A recognized expert on the Microsoft .NET Framework, he’s a former Microsoft MVP award winner and a presenter at conferences and user group meetings.

comments powered by Disqus

Featured

Subscribe on YouTube