Summary of. Net asynchronous programming Modes

Source: Internet
Author: User


Use. Net asynchronous programming, inProgramCall the. NET class method at the same time until the specified callback is executed. or, if the callback is not provided, the call is blocked, polling, or waiting for completion. For example, a program can call a method to enumerate a large list, and the main program will continue to execute. After completing the enumeration, callback and the program addressing it.

Asynchronous programming is composedMany regions of the. NET Framework support the following features:

    • FileIo, stream Io, socket Io

  Using (Filestream FS =   New Filestream ( " C: \ 1.txt " , Filemode. openorcreate ))
{
FS. beginwrite (.
FS. beginread (.
}

 

Socketinformation Si =   New Socketinformation ();
Using (Socket s =   New Socket (SI ))
{
S. beginaccept ();
S. beginreceive ();
S. beginsend ();
S. beginconnect ();
}

 

    • Network:HTTP and TCP Remote processing channel (HTTP, TCP) and proxy
  Httpwebrequest request = (Httpwebrequest) webrequest. Create ( " Http://quitgame.cnblogs.com " );
{
Request. begingetresponse ();
}

 

    • UseXML Web Services created by ASP. NET

The method XXX and vs.net in WebService will automatically generate the corresponding three methods in the client proxy class: xxx/beginxxx/endxxx. We can call beginxxx to complete asynchronous operations.

Client Asynchronous Method Introduction

Of course, if you want to, you can also implement asynchronous calls on the server side.

Introduction to server-side asynchronous Methods

It is worth mentioning that in ASP. net2.0, the asynchronous mode of WebService has changed to the event mode, that is, the request> wait for the end event. For web method XX, vs. NET 2005 will generate xxasync method and xxcompleted event, which is essentially the same as beginxx, endxx mode, but for client program writers, write asynchronous operationsCodeIt becomes simpler-you do not need to deal with the iasync interface. Click here to learn more.

    • ASP. NET web forms

Currently, ASP. NET can implement asynchronous web operations through Ajax and atals (implemented by Microsoft Ajax.

Atlas website on msdn

ASP. NET "Atlas" Official Website

ASP. NET "Atlas" preview document

Atlas quick start tutorial

    • Message Queue for Message Processing on MSMQ

With Microsoft Message Queue (MSMQ), application developers can easily communicate with applications quickly and reliably by sending and receiving messages. Message Processing provides you with reliable fault prevention methods that ensure message transmission and perform many business processes.

Like XML Web Services and. Net remoting, MSMQ is a distributed development technology. However, when using XML Web Services or. NET remoting components, the client needs to exchange information with the server in real time, and the server needs to stay online. MSMQ can work when the server is offline. The message is temporarily stored in the client message queue, and then sent to the server for processing when the server is online.

Obviously, MSMQ is not suitable for the case where the client needs a timely response from the server. MSMQ interacts with the server asynchronously, not
It worries about waiting for a long time to process the server.

Example

    • Asynchronous Delegation

The delegate has the invoke, begininvoke, and endinvoke methods. After instantiating a delegate, you can call the delegate's begininvoke method to complete asynchronous operations.
This is a very useful and simple method. When performing custom operations, using asynchronous delegation is the most elegant way-you do not need to manage thread resources on your own. Asynchronous delegation can be said to be the core of the asynchronous transformation of DOTNET into the mode. Many built-in asynchronous programming modes of DOTNET are basically implemented through asynchronous delegation.

For more information about asynchronous delegation, see the msdn documentation.

To sum up, the essence of asynchronous calling is to use a new thread to complete the work, avoiding blocking on the current thread (generally interface thread or main thread. With the implementation of the isynchronizeinvoke interface,. NET provides perfect support for asynchronous operations, just as it provides perfect support for reflection.

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.