예제 #1
0
        public ForegroundThreadAffinitizedObject(bool assertIsForeground = false)
        {
            _foregroundThreadDataWhenCreated = CurrentForegroundThreadData;

            // For sanity's sake, ensure that our idea of "foreground" is the same as WPF's. But we won't assert
            // anything if we haven't figured it out yet.
            Contract.ThrowIfFalse(
                CurrentForegroundThreadData.Kind == ForegroundThreadDataKind.Unknown ||
                Application.Current == null ||
                Application.Current.Dispatcher.Thread == ForegroundThread);

            // ForegroundThreadAffinitizedObject might not necessarily be created on a foreground thread.
            // AssertIsForeground here only if the object must be created on a foreground thread.
            if (assertIsForeground)
            {
                AssertIsForeground();
            }
        }
예제 #2
0
 // HACK: This is a dangerous way of establishing the 'foreground' thread affinity of an
 // AppDomain.  This method should be deleted in favor of forcing derivations of this type
 // to either explicitly inherit WPF Dispatcher thread or provide an explicit thread
 // they believe to be the foreground.
 static ForegroundThreadAffinitizedObject()
 {
     s_fallbackForegroundThreadData = ForegroundThreadData.CreateDefault(Unknown);
 }