博文

目前显示的是 八月, 2020的博文

Await - Async in C#

  await - async  in C# WPF Sample1:  without UI controll var webclient = new WebClient(); var downThread = new Thread( ()=> { var result = webclient.DownloadString("http://www.google.com"); MessageBox.Show(result); }); downThread.Start(); Sample2: still without UI controll. runButton.IsEnabled= false; var webclient = new WebClient(); var downThread = new Thread( ()=> { var result = webclient.DownloadString("http://www.google.com"); MessageBox.Show(result); }); downThread.Start(); runButton.IsEnabled= true; Sample3: error. runButton.IsEnabled= false; var webclient = new WebClient(); var downThread = new Thread( ()=> {     var result = webclient.DownloadString("http://www.google.com");     MessageBox.Show(result);     runButton.IsEnabled= true;  // is going to crash. error . }); downThread.Start(); Sample4: Dispatcher.Invoke runButton.IsEnabled= false; var webclient = new WebClient(); var downThread = new Thread( ()=> {     var result = webclien