DispatcherObject.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / System / Windows / Threading / DispatcherObject.cs / 1305600 / DispatcherObject.cs

                            using System; 
using System.Windows;
using System.Threading;
using MS.Internal.WindowsBase;               // FriendAccessAllowed
 
namespace System.Windows.Threading
{ 
    ///  
    ///     A DispatcherObject is an object associated with a
    ///     .  A DispatcherObject instance should 
    ///     only be access by the dispatcher's thread.
    /// 
    /// 
    ///     Subclasses of  should enforce thread 
    ///     safety by calling  on all their public
    ///     methods to ensure the calling thread is the appropriate thread. 
    ///      
    ///     DispatcherObject cannot be independently instantiated; that is,
    ///     all constructors are protected. 
    /// 
    public abstract class DispatcherObject
    {
        ///  
        ///     Returns the  that this
        ///      is associated with. 
        ///  
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
        public Dispatcher Dispatcher 
        {
            get
            {
                // This property is free-threaded. 

                return _dispatcher; 
            } 
        }
 
        // This method allows certain derived classes to break the dispatcher affinity
        // of our objects.
        [FriendAccessAllowed] // Built into Base, also used by Framework.
        internal void DetachFromDispatcher() 
        {
            _dispatcher = null; 
         } 

        ///  
        ///     Checks that the calling thread has access to this object.
        /// 
        /// 
        ///     Only the dispatcher thread may access DispatcherObjects. 
        ///     

/// This method is public so that any thread can probe to /// see if it has access to the DispatcherObject. /// /// /// True if the calling thread has access to this object. /// [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public bool CheckAccess() { // This method is free-threaded. bool accessAllowed = true; Dispatcher dispatcher = _dispatcher; // Note: a DispatcherObject that is not associated with a // dispatcher is considered to be free-threaded. if(dispatcher != null) { accessAllowed = dispatcher.CheckAccess(); } return accessAllowed; } ///

/// Verifies that the calling thread has access to this object. /// /// /// Only the dispatcher thread may access DispatcherObjects. ///

/// This method is public so that derived classes can probe to /// see if the calling thread has access to itself. /// [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public void VerifyAccess() { // This method is free-threaded. Dispatcher dispatcher = _dispatcher; // Note: a DispatcherObject that is not associated with a // dispatcher is considered to be free-threaded. if(dispatcher != null) { dispatcher.VerifyAccess(); } } ///

/// Instantiate this object associated with the current Dispatcher. /// protected DispatcherObject() { _dispatcher = Dispatcher.CurrentDispatcher; } private Dispatcher _dispatcher; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Windows; using System.Threading; using MS.Internal.WindowsBase; // FriendAccessAllowed namespace System.Windows.Threading { /// /// A DispatcherObject is an object associated with a /// . A DispatcherObject instance should /// only be access by the dispatcher's thread. /// /// /// Subclasses of should enforce thread /// safety by calling on all their public /// methods to ensure the calling thread is the appropriate thread. /// /// DispatcherObject cannot be independently instantiated; that is, /// all constructors are protected. /// public abstract class DispatcherObject { /// /// Returns the that this /// is associated with. /// [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)] public Dispatcher Dispatcher { get { // This property is free-threaded. return _dispatcher; } } // This method allows certain derived classes to break the dispatcher affinity // of our objects. [FriendAccessAllowed] // Built into Base, also used by Framework. internal void DetachFromDispatcher() { _dispatcher = null; } /// /// Checks that the calling thread has access to this object. /// /// /// Only the dispatcher thread may access DispatcherObjects. ///

/// This method is public so that any thread can probe to /// see if it has access to the DispatcherObject. /// /// /// True if the calling thread has access to this object. /// [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public bool CheckAccess() { // This method is free-threaded. bool accessAllowed = true; Dispatcher dispatcher = _dispatcher; // Note: a DispatcherObject that is not associated with a // dispatcher is considered to be free-threaded. if(dispatcher != null) { accessAllowed = dispatcher.CheckAccess(); } return accessAllowed; } ///

/// Verifies that the calling thread has access to this object. /// /// /// Only the dispatcher thread may access DispatcherObjects. ///

/// This method is public so that derived classes can probe to /// see if the calling thread has access to itself. /// [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)] public void VerifyAccess() { // This method is free-threaded. Dispatcher dispatcher = _dispatcher; // Note: a DispatcherObject that is not associated with a // dispatcher is considered to be free-threaded. if(dispatcher != null) { dispatcher.VerifyAccess(); } } ///

/// Instantiate this object associated with the current Dispatcher. /// protected DispatcherObject() { _dispatcher = Dispatcher.CurrentDispatcher; } private Dispatcher _dispatcher; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK