Ending an Asynchronous Operation
The EndOperationName method ends asynchronous operation OperationName. The return value of the EndOperationName method is the same type returned by its synchronous counterpart and is specific to the asynchronous operation. For example, the EndRead method returns the number of bytes read from a FileStream and the EndGetHostByName method returns an IPHostEntry object that contains information about a host computer. The EndOperationName method takes any out or ref parameters declared in the signature of the synchronous version of the method. In addition to the parameters from the synchronous method, the EndOperationName method also includes an IAsyncResult parameter. Callers must pass the instance returned by the corresponding call to BeginOperationName.
If the asynchronous operation represented by the IAsyncResult object has not completed when EndOperationName is called, EndOperationName blocks the calling thread until the asynchronous operation is complete. Exceptions thrown by the asynchronous operation are thrown from the EndOperationName method. The effect of calling the EndOperationName method multiple times with the same IAsyncResult is not defined. Likewise, calling the EndOperationName method with an IAsyncResult that was not returned by the related Begin method is also not defined.
Note: |
---|
Implementers of this design pattern should notify the caller that the asynchronous operation completed by setting
IsCompleted to true, calling the asynchronous callback method (if one was specified) and signaling the AsyncWaitHandle.
|
Application developers have several design choices for accessing the results of the asynchronous operation. The correct choice depends on whether the application has instructions that can execute while the operation completes. If an application cannot perform any additional work until it receives the results of the asynchronous operation, the application must block until the results are available. To block until an asynchronous operation completes, you can use one of the following approaches:
Applications that do not need to block while the asynchronous operation completes can use one of the following approaches: