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

  1. //------------------------------------------------------------------------------
  2. // <copyright file="AsyncOperationManager.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.Collections;
  18.     using System.Threading;
  19.     using System.Diagnostics;
  20.     using System.Security.Permissions;
  21.    
  22.     [HostProtection(SharedState = true)]
  23.     public static class AsyncOperationManager
  24.     {
  25.         public static AsyncOperation CreateOperation(object userSuppliedState)
  26.         {
  27.             return AsyncOperation.CreateOperation(userSuppliedState, SynchronizationContext);
  28.         }
  29.        
  30.         /// <include file='doc\AsyncOperationManager.uex' path='docs/doc[@for="AsyncOperationManager.SynchronizationContext"]/*' />
  31.         [EditorBrowsable(EditorBrowsableState.Advanced)]
  32.         public static SynchronizationContext SynchronizationContext {
  33.             get {
  34.                 if (SynchronizationContext.Current == null) {
  35.                     SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
  36.                 }
  37.                
  38.                 return SynchronizationContext.Current;
  39.             }
  40.            
  41.             // a thread should set this to null when it is done, else the context will never be disposed/GC'd
  42.             [PermissionSetAttribute(SecurityAction.LinkDemand, Name = "FullTrust")]
  43.             set { SynchronizationContext.SetSynchronizationContext(value); }
  44.         }
  45.     }
  46. }

Developer Fusion