Пример #1
0
 public SchedulerProvider()
 {
     Task         = new TaskScheduler();
     IOCompletion = new IOCompletionScheduler();
     Current      = new CurrentScheduler();
     Immediate    = new ImmediateScheduler();
     NewThread    = new NewThreadScheduler();
     ThreadPool   = new ThreadPoolScheduler();
 }
Пример #2
0
 public SchedulerProvider()
 {
     Task = new TaskScheduler();
     IOCompletion = new IOCompletionScheduler();
     Current = new CurrentScheduler();
     Immediate = new ImmediateScheduler();
     NewThread = new NewThreadScheduler();
     ThreadPool = new ThreadPoolScheduler();
 }
        /**
         * Scheduler控制订阅和通知的发送。
         * Scheduler包含三个组件:1)一个优先队列存放任务,2)Execution context,用来决定任务在哪执行(线程池,当前线程)3)scheduler的时钟,Task是根据这个时钟调度的,不是系统时钟。
         *
         * rx中所有的Scheduler实现IScheduler接口。
         *
         */

        public static void GetSchedulers()
        {
            //立刻在当前线程上执行
            ImmediateScheduler immediate = Scheduler.Immediate;
            //在当前线程上尽可能快的执行(先放到队列中,尽快执行)
            CurrentThreadScheduler currentThreadScheduler = Scheduler.CurrentThread;
            //每次创建一个线程执行
            NewThreadScheduler newThreadScheduler = NewThreadScheduler.Default;
            //在Task Factory上执行
            TaskPoolScheduler taskPoolScheduler = TaskPoolScheduler.Default;

            //在当前Dispatcher上执行任务
            DispatcherScheduler dispatcherScheduler = DispatcherScheduler.Current;

            //在ThreadPool上执行
            ThreadPoolScheduler threadPoolScheduler = ThreadPoolScheduler.Instance;
            //默认的调度器  其原则是使用最小的并行性,for operators returning an observable with a finite and small number of messages, Rx calls Immediate.  For operators returning a potentially large or infinite number of messages, CurrentThread is called. For operators which use timers, ThreadPool is used.
            DefaultScheduler defaultScheduler = Scheduler.Default;
        }
Пример #4
0
 public Schedulers(DispatcherScheduler dispatcher, DefaultScheduler threadPool, ImmediateScheduler immediate)
 => (_dispatcher, _threadPool, _immediate) = (dispatcher, threadPool, immediate);