1. Event-based Asynchronous Pattern (EAP):
Similar to XmlHttpRequest in Ajax, the processing is not completed after send, but is notified in the onreadystatechange event that the processing is completed.
WebClient wc = new WebClient();
wc.DownloadStringCompleted += Wc_DownloadStringCompleted;
wc.DownloadStringAsync(new Uri("http://www.jiyuwu.com"));
private void Wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { MessageBox.Show(e.Result); }
The advantage is that it is simple, but the disadvantage is that it is very troublesome to implement complex services, such as downloading b after downloading A is successful. If downloading b is successful, then download c, otherwise, download d. The characteristics of the EAP class are: an asynchronous method with a ***Completed event. There are relatively few EAP-based classes in .Net. There are better alternatives too, so know that.