/// <Summary> /// Asynchronous request object /// </Summary> Public class AsyncResult: IAsyncResult { Static readonly object lockObject = new object (); Private ManualResetEvent completeEvent = null;
# Region IAsyncResult Member /// <Summary> /// Initialization /// </Summary> /// <Param name = "cb"> callback method </param> /// <Param name = "asyncState"> User status data </param> Internal AsyncResult (AsyncCallback cb, object asyncState) { This. Callback = cb; This. AsyncState = asyncState; This. IsCompleted = false; This. ParentResult = null; This. Exception = null; This. State = null; } /// <Summary> /// Obtain user status data /// </Summary> Public object AsyncState { Get; Internal set; } /// <Summary> /// Obtain or set custom status data /// </Summary> Public object State { Get; Set; } /// <Summary> /// Asynchronous wait handle /// </Summary> Public System. Threading. WaitHandle AsyncWaitHandle { Get { Lock (lockObject) { If (this. completeEvent = null) This. completeEvent = new ManualResetEvent (false ); Return this. completeEvent; } } } /// <Summary> /// Complete the preceding steps /// </Summary> Public bool CompletedSynchronously { Get {return false ;} } /// <Summary> /// Completed /// </Summary> Public bool IsCompleted { Get; Private set; } # Endregion /// <Summary> /// Parent Result. If yes /// </Summary> Public IAsyncResult ParentResult {get; set ;}
/// <Summary> /// Obtain asynchronous call completion /// </Summary> Public AsyncCallback Callback { Get; Internal set; }
/// <Summary> /// Obtain or set exceptions generated during the asynchronous Process /// </Summary> Public Exception {get; set ;}
/// <Summary> /// Completes the request. /// </Summary> Public void Completed () { This. IsCompleted = true; Lock (lockObject) { If (this. completeEvent! = Null) This. completeEvent. Set (); } If (this. Callback! = Null) This. Callback (this ); } /// <Summary> /// Completes the request. /// </Summary> Public void Completed (Exception ex ){ This. Exception = ex; This. Completed (); } } |