protected void SetWaitNotificationRequired()
        {
            Type type = this.GetType();

            if (SynchronizationContext.s_cachedPreparedType1 != type && SynchronizationContext.s_cachedPreparedType2 != type && (SynchronizationContext.s_cachedPreparedType3 != type && SynchronizationContext.s_cachedPreparedType4 != type) && SynchronizationContext.s_cachedPreparedType5 != type)
            {
                RuntimeHelpers.PrepareDelegate((Delegate) new SynchronizationContext.WaitDelegate(this.Wait));
                if (SynchronizationContext.s_cachedPreparedType1 == (Type)null)
                {
                    SynchronizationContext.s_cachedPreparedType1 = type;
                }
                else if (SynchronizationContext.s_cachedPreparedType2 == (Type)null)
                {
                    SynchronizationContext.s_cachedPreparedType2 = type;
                }
                else if (SynchronizationContext.s_cachedPreparedType3 == (Type)null)
                {
                    SynchronizationContext.s_cachedPreparedType3 = type;
                }
                else if (SynchronizationContext.s_cachedPreparedType4 == (Type)null)
                {
                    SynchronizationContext.s_cachedPreparedType4 = type;
                }
                else if (SynchronizationContext.s_cachedPreparedType5 == (Type)null)
                {
                    SynchronizationContext.s_cachedPreparedType5 = type;
                }
            }
            this._props = this._props | SynchronizationContextProperties.RequireWaitNotification;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Verifies that a <see cref="SynchronizationContext"/> satisfies the guarantees required by the calling code.
        /// </summary>
        /// <param name="synchronizationContextType">The type derived from <see cref="SynchronizationContext"/> to test.</param>
        /// <param name="properties">The guarantees required by the calling code.</param>
        public static void Verify(Type synchronizationContextType, SynchronizationContextProperties properties)
        {
            SynchronizationContextProperties supported = Lookup(synchronizationContextType);

            if ((supported & properties) != properties)
            {
                throw new InvalidOperationException("This asynchronous object cannot be used with this SynchronizationContext");
            }
        }
        // protected so that only the derived sync context class can enable these flags
        protected void SetWaitNotificationRequired()
        {
            // Prepare the method so that it can be called in a reliable fashion when a wait is needed.
            // This will obviously only make the Wait reliable if the Wait method is itself reliable. The only thing
            // preparing the method here does is to ensure there is no failure point before the method execution begins.

            RuntimeHelpers.PrepareDelegate(new WaitDelegate(this.Wait));
            _props |= SynchronizationContextProperties.RequireWaitNotification;
        }
 /// <summary>
 /// Verifies that <see cref="SynchronizationContext.Current"/> satisfies the guarantees required by the calling code.
 /// </summary>
 /// <param name="properties">The guarantees required by the calling code.</param>
 public static void Verify(SynchronizationContextProperties properties)
 {
     if (SynchronizationContext.Current == null)
     {
         Verify(typeof(SynchronizationContext), properties);
     }
     else
     {
         Verify(SynchronizationContext.Current.GetType(), properties);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// Looks up the guarantees for a <see cref="SynchronizationContext"/> type.
        /// </summary>
        /// <param name="synchronizationContextType">The type derived from <see cref="SynchronizationContext"/> to test.</param>
        /// <returns>The properties guaranteed by <paramref name="synchronizationContextType"/>.</returns>
        public static SynchronizationContextProperties Lookup(Type synchronizationContextType)
        {
            lock (synchronizationContextProperties)
            {
                SynchronizationContextProperties supported = SynchronizationContextProperties.None;
                if (synchronizationContextProperties.ContainsKey(synchronizationContextType.FullName))
                {
                    supported = synchronizationContextProperties[synchronizationContextType.FullName];
                }

                return(supported);
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Registers a <see cref="SynchronizationContext"/> type claiming to provide certain guarantees.
 /// </summary>
 /// <param name="synchronizationContextType">The type derived from <see cref="SynchronizationContext"/>.</param>
 /// <param name="properties">The guarantees provided by this type.</param>
 /// <remarks>
 /// <para>This method should be called once for each type of <see cref="SynchronizationContext"/>. It is not necessary to call this method for .NET <see cref="SynchronizationContext"/> types or <see cref="ActionDispatcherSynchronizationContext"/>.</para>
 /// <para>If this method is called more than once for a type, the new value of <paramref name="properties"/> replaces the old value. The flags are not merged.</para>
 /// </remarks>
 public static void Register(Type synchronizationContextType, SynchronizationContextProperties properties)
 {
     lock (synchronizationContextProperties)
     {
         if (synchronizationContextProperties.ContainsKey(synchronizationContextType.FullName))
         {
             synchronizationContextProperties[synchronizationContextType.FullName] = properties;
         }
         else
         {
             synchronizationContextProperties.Add(synchronizationContextType.FullName, properties);
         }
     }
 }
        /// <summary>
        /// Registers a <see cref="SynchronizationContext"/> type claiming to provide certain guarantees.
        /// </summary>
        /// <param name="synchronizationContextType">The type derived from <see cref="SynchronizationContext"/>. May not be <c>null</c>.</param>
        /// <param name="properties">The guarantees provided by this type.</param>
        /// <remarks>
        /// <para>This method should be called once for each type of <see cref="SynchronizationContext"/>. It is not necessary to call this method for .NET <see cref="SynchronizationContext"/> types or <see cref="ActionDispatcherSynchronizationContext"/>.</para>
        /// <para>If this method is called more than once for a type, the new value of <paramref name="properties"/> replaces the old value. The flags are not merged.</para>
        /// </remarks>
        public static void Register(Type synchronizationContextType, SynchronizationContextProperties properties)
        {
            Contract.Requires(synchronizationContextType != null);

            lock (synchronizationContextProperties)
            {
                if (synchronizationContextProperties.ContainsKey(synchronizationContextType.FullName))
                {
                    synchronizationContextProperties[synchronizationContextType.FullName] = properties;
                }
                else
                {
                    synchronizationContextProperties.Add(synchronizationContextType.FullName, properties);
                }
            }
        }
        protected void SetWaitNotificationRequired()
        {
            //
            // Prepare the method so that it can be called in a reliable fashion when a wait is needed.
            // This will obviously only make the Wait reliable if the Wait method is itself reliable. The only thing
            // preparing the method here does is to ensure there is no failure point before the method execution begins.
            //
            // Preparing the method in this way is quite expensive, but only needs to be done once per type, per AppDomain.
            // So we keep track of a few types we've already prepared in this AD.  It is uncommon to have more than
            // a few SynchronizationContext implementations, so we only cache the first five we encounter; this lets
            // our cache be much faster than a more general cache might be.  This is important, because this
            // is a *very* hot code path for many WPF and WinForms apps.
            //
            Type type = this.GetType();

            if (s_cachedPreparedType1 != type &&
                s_cachedPreparedType2 != type &&
                s_cachedPreparedType3 != type &&
                s_cachedPreparedType4 != type &&
                s_cachedPreparedType5 != type)
            {
                RuntimeHelpers.PrepareDelegate(new WaitDelegate(this.Wait));

                if (s_cachedPreparedType1 == null)
                {
                    s_cachedPreparedType1 = type;
                }
                else if (s_cachedPreparedType2 == null)
                {
                    s_cachedPreparedType2 = type;
                }
                else if (s_cachedPreparedType3 == null)
                {
                    s_cachedPreparedType3 = type;
                }
                else if (s_cachedPreparedType4 == null)
                {
                    s_cachedPreparedType4 = type;
                }
                else if (s_cachedPreparedType5 == null)
                {
                    s_cachedPreparedType5 = type;
                }
            }

            _props |= SynchronizationContextProperties.RequireWaitNotification;
        }
Exemplo n.º 9
0
        protected void SetWaitNotificationRequired()
        {
            //
            // Prepare the method so that it can be called in a reliable fashion when a wait is needed.
            // This will obviously only make the Wait reliable if the Wait method is itself reliable. The only thing
            // preparing the method here does is to ensure there is no failure point before the method execution begins.
            //
            // Preparing the method in this way is quite expensive, but only needs to be done once per type, per AppDomain.
            // So we keep track of a few types we've already prepared in this AD.  It is uncommon to have more than
            // a few SynchronizationContext implementations, so we only cache the first five we encounter; this lets
            // our cache be much faster than a more general cache might be.  This is important, because this
            // is a *very* hot code path for many WPF and WinForms apps.
            //
            Type type = this.GetType();
            if (s_cachedPreparedType1 != type &&
                s_cachedPreparedType2 != type &&
                s_cachedPreparedType3 != type &&
                s_cachedPreparedType4 != type &&
                s_cachedPreparedType5 != type)
            {
                RuntimeHelpers.PrepareDelegate(new WaitDelegate(this.Wait));

                if (s_cachedPreparedType1 == null)      s_cachedPreparedType1  = type;
                else if (s_cachedPreparedType2 == null) s_cachedPreparedType2  = type;
                else if (s_cachedPreparedType3 == null) s_cachedPreparedType3  = type;
                else if (s_cachedPreparedType4 == null) s_cachedPreparedType4  = type;
                else if (s_cachedPreparedType5 == null) s_cachedPreparedType5  = type;
            }

            _props |= SynchronizationContextProperties.RequireWaitNotification;
        }
 // protected so that only the derived sync context class can enable these flags
 protected void SetWaitNotificationRequired()
 {   
     // Prepare the method so that it can be called in a reliable fashion when a wait is needed.
     // This will obviously only make the Wait reliable if the Wait method is itself reliable. The only thing
     // preparing the method here does is to ensure there is no failure point before the method execution begins.
         
     RuntimeHelpers.PrepareDelegate(new WaitDelegate(this.Wait));
     _props |= SynchronizationContextProperties.RequireWaitNotification;
 }
 protected void SetWaitNotificationRequired()
 {
     RuntimeHelpers.PrepareDelegate(new WaitDelegate(this.Wait));
     this._props |= SynchronizationContextProperties.RequireWaitNotification;
 }
Exemplo n.º 12
0
 // protected so that only the derived sync context class can enable these flags
 protected void SetWaitNotificationRequired()
 {
     _props |= SynchronizationContextProperties.RequireWaitNotification;
 }
Exemplo n.º 13
0
 protected void SetWaitNotificationRequired()
 {
     RuntimeHelpers.PrepareDelegate(new WaitDelegate(this.Wait));
     this._props |= SynchronizationContextProperties.RequireWaitNotification;
 }
 /// <summary>
 /// Verifies that <see cref="SynchronizationContext.Current"/> satisfies the guarantees required by the calling code.
 /// </summary>
 /// <param name="properties">The guarantees required by the calling code.</param>
 public static void Verify(SynchronizationContextProperties properties)
 {
     if (SynchronizationContext.Current == null)
     {
         Verify(typeof(SynchronizationContext), properties);
     }
     else
     {
         Verify(SynchronizationContext.Current.GetType(), properties);
     }
 }
 /// <summary>
 /// Verifies that a <see cref="SynchronizationContext"/> satisfies the guarantees required by the calling code.
 /// </summary>
 /// <param name="synchronizationContextType">The type derived from <see cref="SynchronizationContext"/> to test.</param>
 /// <param name="properties">The guarantees required by the calling code.</param>
 public static void Verify(Type synchronizationContextType, SynchronizationContextProperties properties)
 {
     SynchronizationContextProperties supported = Lookup(synchronizationContextType);
     if ((supported & properties) != properties)
     {
         throw new InvalidOperationException("This asynchronous object cannot be used with this SynchronizationContext");
     }
 }