The Labs \ Source Viewer \ SSCLI \ System.ComponentModel \ AsyncCompletedEventArgs

  1. //------------------------------------------------------------------------------
  2. // <copyright file="AsyncCompletedEventArgs.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. namespace System.ComponentModel
  16. {
  17.     using System.Diagnostics.CodeAnalysis;
  18.     using System.Security.Permissions;
  19.     using System.Reflection;
  20.    
  21.     [HostProtection(SharedState = true)]
  22.     public class AsyncCompletedEventArgs : System.EventArgs
  23.     {
  24.         private readonly Exception error;
  25.         private readonly bool cancelled;
  26.         private readonly object userState;
  27.        
  28.         public AsyncCompletedEventArgs(Exception error, bool cancelled, object userState)
  29.         {
  30.             this.error = error;
  31.             this.cancelled = cancelled;
  32.             this.userState = userState;
  33.         }
  34.        
  35.         [SRDescription(SR.Async_AsyncEventArgs_Cancelled)]
  36.         public bool Cancelled {
  37.             get { return cancelled; }
  38.         }
  39.        
  40.         [SRDescription(SR.Async_AsyncEventArgs_Error)]
  41.         public Exception Error {
  42.             get { return error; }
  43.         }
  44.        
  45.         [SRDescription(SR.Async_AsyncEventArgs_UserState)]
  46.         public object UserState {
  47.             get { return userState; }
  48.         }
  49.        
  50.         // Call from every result 'getter'. Will throw if there's an error or operation was cancelled
  51.         //
  52.         [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate")]
  53.         protected void RaiseExceptionIfNecessary()
  54.         {
  55.             if (Error != null) {
  56.                 throw new TargetInvocationException(SR.GetString(SR.Async_ExceptionOccurred), Error);
  57.             }
  58.             else if (Cancelled) {
  59.                 throw new InvalidOperationException(SR.GetString(SR.Async_OperationCancelled));
  60.             }
  61.            
  62.         }
  63.        
  64.     }
  65. }

Developer Fusion