Page 180 - DCAP507_SYSTEM_SOFTWARE
P. 180

System Software




                    Notes
                                     Member                 Description
                                     AsyncState             An  optional  application-specific  object  that  contains
                                                            information regarding the asynchronous operation.
                                     AsyncWaitHandle        A WaitHandle that  can  be  used  to  block  application
                                                            implementation   until   the   asynchronous   operation
                                                            completes.
                                     CompletedSynchronously   A value that indicates whether the asynchronous operation
                                                            completed  on  the  thread  used  to  call  BeginOperation
                                                            Name instead of completing on a separate ThreadPoolthread.

                                     IsCompleted            A value that signifies whether the asynchronous operation
                                                            has finished.

                                   A Begin Operation Name method takes any parameters stated in the signature of the synchronous
                                   edition of the method that are passed by value or by reference. Any out parameters are not part
                                   of the Begin Operation Namemethod signature. The  BeginOperationName method signature
                                   also involves two additional parameters. The first of these defines an AsyncCallback delegate
                                   that references a technique that is called when the asynchronous operation finishes. The caller
                                   can specify null (Nothing in Visual Basic) if it does not want a technique invoked when the
                                   operation completes. The second additional parameter is a user-defined object. This object can
                                   be  used  to  pass  application-specific  state  information  to  the  technique  raised  when  the
                                   asynchronous operation completes. If a BeginOperationName method takes additional operation-
                                   specific parameters, like a byte array to amass bytes read from a file, the AsyncCallback and
                                   application state object are the last parameters in the BeginOperation Namemethod signature.

                                   Begin OperationName returns control to the calling thread instantly. If the BeginOperationName
                                   technique throws exceptions, the exceptions are thrown previous to the asynchronous operation
                                   is started.



                                     Did u know?  If the BeginOperationNamemethod throws exceptions, the callback method
                                     is not invoked.

                                   11.2.2 Ending an Asynchronous Operation

                                   The End Operation Name technique ends asynchronous operation OperationName. The return
                                   value  of  the  EndOperationName  method  is  the  same  type  returned  by its  synchronous
                                   counterpart and is particular to the asynchronous operation.


                                          Example: The EndRead method returns the number of bytes read from a FileStream and
                                   the  EndGetHostByName method  returns an  IPHostEntry  object that includes  information
                                   regarding a host computer.

                                   The EndOperationName method takes any out or ref parameters stated in the signature of the
                                   synchronous edition of the method. In addition to the parameters from the synchronous method,
                                   the EndOperationName method also contains an IAsyncResult parameter.

                                       !
                                     Caution   Callers  must  pass  the  instance  returned  by  the  analogous  call  to
                                     BeginOperationName.



          174                               LOVELY PROFESSIONAL UNIVERSITY
   175   176   177   178   179   180   181   182   183   184   185