Beispiel #1
0
        internal static ForegroundThreadDataKind CreateDefault(ForegroundThreadDataKind defaultKind)
        {
            var syncContextTypeName = SynchronizationContext.Current?.GetType().FullName;

            switch (syncContextTypeName)
            {
            case "System.Windows.Threading.DispatcherSynchronizationContext":

                return(Wpf);

            case "Microsoft.VisualStudio.Threading.JoinableTask+JoinableTaskSynchronizationContext":

                return(JoinableTask);

            case "System.Windows.Forms.WindowsFormsSynchronizationContext":

                return(WinForms);

            case "MonoDevelop.Ide.DispatchService+GtkSynchronizationContext":

                return(MonoDevelopGtk);

            case "Xwt.XwtSynchronizationContext":

                return(MonoDevelopXwt);

            default:

                return(defaultKind);
            }
        }
        /// <summary>
        /// Creates the default ForegroundThreadData assuming that the current thread is the UI thread.
        /// </summary>
        /// <param name="defaultKind">The ForegroundThreadDataKind to fall back to if a UI thread cannot be found</param>
        /// <returns>default ForegroundThreadData values</returns>
        internal static ForegroundThreadData CreateDefault(ForegroundThreadDataKind defaultKind)
        {
            var kind = ForegroundThreadDataInfo.CreateDefault(defaultKind);

            // None of the work posted to the foregroundTaskScheduler should block pending keyboard/mouse input from the user.
            // So instead of using the default priority which is above user input, we use Background priority which is 1 level
            // below user input.
            var taskScheduler = new SynchronizationContextTaskScheduler(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher, DispatcherPriority.Background));

            return(new ForegroundThreadData(Thread.CurrentThread, taskScheduler, kind));
        }
        /// <summary>
        /// Creates the default ForegroundThreadData assuming that the current thread is the UI thread.
        /// </summary>
        /// <param name="defaultKind">The ForegroundThreadDataKind to fall back to if a UI thread cannot be found</param>
        /// <returns>default ForegroundThreadData values</returns>
        internal static ForegroundThreadData CreateDefault(ForegroundThreadDataKind defaultKind)
        {
            var kind = ForegroundThreadDataInfo.CreateDefault(defaultKind);

            // None of the work posted to the foregroundTaskScheduler should block pending keyboard/mouse input from the user.
            // So instead of using the default priority which is above user input, we use Background priority which is 1 level
            // below user input.
            var taskScheduler = new SynchronizationContextTaskScheduler(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher, DispatcherPriority.Background));

            return new ForegroundThreadData(Thread.CurrentThread, taskScheduler, kind);
        }
Beispiel #4
0
        internal static ForegroundThreadData CreateDefault()
        {
            ForegroundThreadDataKind kind = SynchronizationContext.Current?.GetType().FullName == "System.Windows.Threading.DispatcherSynchronizationContext"
                    ? ForegroundThreadDataKind.Wpf
                    : ForegroundThreadDataKind.Unknown;

            // None of the work posted to the foregroundTaskScheduler should block pending keyboard/mouse input from the user.
            // So instead of using the default priority which is above user input, we use Background priority which is 1 level
            // below user input.
            var taskScheduler = new SynchronizationContextTaskScheduler(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher, DispatcherPriority.Background));

            return(new ForegroundThreadData(Thread.CurrentThread, taskScheduler, kind));
        }
        internal static ForegroundThreadDataKind CreateDefault(ForegroundThreadDataKind defaultKind)
        {
            var syncConextTypeName = SynchronizationContext.Current?.GetType().FullName;

            switch (syncConextTypeName)
            {
                case "System.Windows.Threading.DispatcherSynchronizationContext":

                    return Wpf;

                case "Microsoft.VisualStudio.Threading.JoinableTask+JoinableTaskSynchronizationContext":

                    return JoinableTask;

                default:

                    return defaultKind;
            }
        }
        internal static ForegroundThreadDataKind CreateDefault(ForegroundThreadDataKind defaultKind)
        {
            var syncConextTypeName = SynchronizationContext.Current?.GetType().FullName;

            switch (syncConextTypeName)
            {
            case "System.Windows.Threading.DispatcherSynchronizationContext":

                return(Wpf);

            case "Microsoft.VisualStudio.Threading.JoinableTask+JoinableTaskSynchronizationContext":

                return(JoinableTask);

            default:

                return(defaultKind);
            }
        }
 internal ForegroundThreadData(Thread thread, TaskScheduler taskScheduler, ForegroundThreadDataKind kind)
 {
     Thread        = thread;
     TaskScheduler = taskScheduler;
     Kind          = kind;
 }
 internal ForegroundThreadData(Thread thread, TaskScheduler taskScheduler, ForegroundThreadDataKind kind)
 {
     Thread = thread;
     TaskScheduler = taskScheduler;
     Kind = kind;
 }
 internal static void SetCurrentForegroundThreadDataKind(ForegroundThreadDataKind? kind)
 {
     s_currentForegroundThreadDataKind = kind;
 }
 static ForegroundThreadDataInfo()
 {
     s_fallbackForegroundThreadDataKind = CreateDefault();
 }
        /// <summary>
        /// Creates the default ForegroundThreadData assuming that the current thread is the UI thread.
        /// </summary>
        /// <param name="defaultKind">The ForegroundThreadDataKind to fall back to if a UI thread cannot be found</param>
        /// <returns>default ForegroundThreadData values</returns>
        internal static ForegroundThreadData CreateDefault(ForegroundThreadDataKind defaultKind)
        {
            var kind = ForegroundThreadDataInfo.CreateDefault(defaultKind);

            return(new ForegroundThreadData(Thread.CurrentThread, new SynchronizationContextTaskScheduler(SynchronizationContext.Current), kind));
        }
Beispiel #12
0
 static ForegroundThreadDataInfo()
 {
     s_fallbackForegroundThreadDataKind = CreateDefault();
 }