The biggest feature of. net 4.5 is the improvement of asynchronous programming. The await async keyword is added to make asynchronous programming as simple as Synchronous Programming. This mode is implemented based on the task parallel library.
Next let's look at a simple wpf program:
Async private void Button_Click_1 (object sender, RoutedEventArgs e)
{
TestTextBox. Text = await test ();
}
Async Task <string> test ()
{
HttpClient httpClient = new HttpClient ();
Return await httpClient. GetStringAsync ("http://www.baidu.com ");
}
Click the next button to asynchronously download content from the Internet and display it on the UI. You no longer need to use Dispatcher. beginInvoke or SynchronizationContext to update the ui information .. The biggest feature of net 4.5 is the improvement of asynchronous programming. The await async keyword is added to make asynchronous programming as simple as Synchronous Programming. This mode is implemented based on the task parallel library.
Next let's look at a simple wpf program:
Async private void Button_Click_1 (object sender, RoutedEventArgs e)
{
TestTextBox. Text = await test ();
}
Async Task <string> test ()
{
HttpClient httpClient = new HttpClient ();
Return await httpClient. GetStringAsync ("http://www.baidu.com ");
}
Click the next button to asynchronously download content from the Internet and display it on the UI. You no longer need to use Dispatcher. beginInvoke or SynchronizationContext to update the ui information.