[Wrox press] asynchronous programming

Source: Internet
Author: User

To wait or not to wait; that is the question! Whether or not to Implement Asynchronous processing is one of the fundamental issues that a developer must answer when invoking function callacross process boundaries. given that the option to invoke an asynchronous call is available, the programmer has to weigh the relative controls of coding synchronous CALS with its Inherent Drawback-when a synchronous call is made, the Calling thread is blocked and has to wait until the function completes. in specified instances, this is an acceptable created coming, as in the case when a program's logic flow shocould not continue until data is retrieved from a database. asynchronous processing, on the other hand, allows more parallelism. A thread that initiates an asynchronous call is not blocked and can therefore do almost any computation while the method is in transit. the case for asynchronous processing becomes very compelling in the enterprise computing space where systems need to handle hundreds of thousands of function call requests and synchronicity may become a barrier to scalability.

 

Having programmed in Visual Basic for most of my professional career, I used to be envious of my c ++ counterparts and their seemingly magical ability to create multi-threaded applications that did any number of parallel tasks, which is a requirement for asynchronous processing. sure, I was able to mimic asynchronous behavior in VB using out-of-process servers and the use of the dreaded Timer control. it worked, but it just wasn' t elegant. and the application definitely didn't scale.

Life became easier with the advent of VB 6 and its ability to use apartment-model threading. in addition, the programmer's arsenal of tools increased with Windows 2000 providing more ways to make asynchronous callusing COM + events, and COM asynchronous interfaces.

Although it's still a non-trivial undertaking,. NET framework makes programming asynchronous processes much easier than before .. net has asynchronous code built in, and asynchronous programming is a feature supported by region areas of. net Framework, including I/O operations, networking, messaging, message queues, async delegates, Asp. net web forms and, of course, Web services.

A common design pattern:
In order to provide a consistent framework for modeling asynchronous processes, the. NET Framework provides an important common design pattern as a core guiding concept. The basic ideas behind this pattern are as follows:

  • The. NET Framework will provide services needed for supporting the asynchronous programming model.
  • It is the client code that decides if a special call shoshould be asynchronous.
  • It is not necessary for a called object to do additional programming to support asynchronous behavior by its clients. The Common Language Runtime infrastructure shocould be able to handle the difference between the caller and called object views.
  • The called object can choose to explicitly support asynchronous behavior, either because it can implement it more efficiently than a general architecture, or it wants to support only asynchronous behavior by its callers. however, it is recommended that such called objects follow the Asynchronous Design Pattern for exposing asynchronous operations.
  • The Common Language Runtime provides type safety. For async delegates, which are explained in the next section, the compiler generates type-safe method signatures for the begininvoke and endinvoke method CILS.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.