using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace UseAwait { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private async void RunIt() { Task task = Task.Factory.StartNew(() => LongCalc(5)); // not block the UI thread await task; progressText.Text = task.Result.ToString(); } private double LongCalc(double r) { Thread.Sleep(3000); return Math.PI * r * r; } private void syncButton_Click(object sender, EventArgs e) { Task task = Task.Factory.StartNew(() => LongCalc(5)); task.Wait(); progressText.Text = task.Result.ToString(); } private void asyncButton_Click(object sender, EventArgs e) { RunIt(); } } }