1 public partial class Form1 : Form 2 { 3 public Form1() 4 { 5 InitializeComponent(); 6 } 7 8 private void Form1_Load(object sender, EventArgs e) 9 { 10 11 } 12 13 private void button1_Click(object sender, EventArgs e) 14 { 15 Console.WriteLine("当前线程:"+ Environment.CurrentManagedThreadId.ToString()); 16 //ConfigureAwait(true) 任务结束后还回到原来的线程 ConfigureAwait(false) 不回到原来的线程 17 //int result = await HeavyJob().ConfigureAwait(true); 18 int result = HeavyJob().Result; 19 this.label1.Text = result.ToString(); 20 Console.WriteLine("当前线程:" + Environment.CurrentManagedThreadId.ToString()); 21 } 22 23 async Task<int> HeavyJob() 24 { 25 await Task.Delay(6000); 26 return 12; 27 } 28 }
HeavyJob().Result会阻塞当前线程,直到标签:HeavyJob,ConfigureAwait,Form1,案例,死锁,线程,result,ToString From: https://www.cnblogs.com/loki135846/p/18301500