Asynchronous programming
Enable an application. The system creates a new process in the memory. A process is a group of resources, including virtual address controls, file handles, and other carriers required to start the program.
Creates a thread kernel object in the process. The thread reflects the actual execution of the program.
By default, a process includes a thread from the beginning of the program to the end of the program.
Thread Pool)
At the beginning, the thread pool of the process was empty. The thread used by the process was created and completed thread execution. Instead of destroying the thread pool, the thread pool was added to the process. If the process requires another thread, the CLR will restore one thread from the pool to save time.
Asynchronous programming mode
1. Wait-until the process is completed, the original thread is interrupted and the Asynchronous Method is completed.
2. Round-Robin: the original thread regularly checks whether the initiating thread is complete. If not, you can continue with other operations.
3. Callback
Begininvoke obtains a thread from the thread pool and runs the reference method when the new thread starts. Returns an object to the calling thread that implements the iasyncresult interface. This interface reference contains
The current status of the asynchronous method. The original thread can continue to execute the method.
Endinvoke obtains the value returned by an asynchronous method call and releases the resources used by the thread. Accepts a reference to an iasyncresult object returned by begininvoke and finds the associated thread.
Wait-till the end Mode
The original thread initiates an asynchronous method call, does some other processing, then stops and waits until the start thread ends.
Iasyncresult ISA = del. begininvoke (3,5, null, null)
Long result = del. endinvoke (IAR)
Round Robin Mode
The original thread initiates an asynchronous method call, and then regularly checks whether the enabled thread is complete using the iscomplete attribute of the iasyncresult object. If the asynchronous method has been completed, the original thread calls endinvoke.
Callback Mode
Wait until the end mode and polling mode, the initial thread continues its own process, knowing that it has enabled the thread to complete.
The difference between the callback mode is that once the initial thread initiates an asynchronous method, it manages itself and does not consider synchronization. When the Asynchronous Method ends, the system calls a user-defined method to process the result, and call the delegate endinvoke method.
The user-defined method is called the callback method.
Void asynccallback (isyncresult IAR)
Iasyncresult iar1 = (Del. begininvoke (3,5, new asyncresult (), null ))
[2014-9-10] asynchronous programming