Exemplo n.º 1
0
        public TestScheduler()
        {
            m_ioServiceScheduler = new IoServiceScheduler();
            var scheduler = new ProxyScheduler(this);

            m_taskFactory            = new TaskFactory(scheduler.AsTplScheduler());
            m_synchronizationContext = new IoServiceSynchronizationContext(m_ioServiceScheduler);
        }
Exemplo n.º 2
0
        public virtual Task Dispatch(Func <Task> function)
        {
            CheckIfDisposed();
            if (function == null)
            {
                throw new ArgumentNullException(nameof(function));
            }

            var task = Task.Factory.StartNew(function,
                                             CancellationToken.None,
                                             TaskCreationOptions.None,
                                             ProxyScheduler.AsTplScheduler()).Unwrap();

            return(task);
        }
            private void init(TaskScheduler controlScheduler, int maxTasksConcurrency)
            {
                if (maxTasksConcurrency <= 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(maxTasksConcurrency));
                }

                m_maxConcurrentTaskBatch = Math.Min(CONCURRENT_TASK_BATCH_LIMIT, maxTasksConcurrency);

                m_exclusiveTaskAdded  = new ThreadSafeSwitch();
                m_concurrentTaskAdded = new ThreadSafeSwitch();

                m_ownControlTaskScheduler = (controlScheduler == null);
                if (m_ownControlTaskScheduler)
                {
                    var ioControlService = new IoServiceScheduler();
                    m_ioControlScheduler = new IoServiceThreadPoolScheduler(ioControlService, CONTROL_SCHEDULER_CONCURRENCY);
                    var controlProxyScheduler = new ProxyScheduler(m_ioControlScheduler);
                    m_controlTaskFactory = new TaskFactory(controlProxyScheduler.AsTplScheduler());
                }
                else
                {
                    m_controlTaskFactory = new TaskFactory(controlScheduler);
                }


                var ioService = new IoServiceScheduler();

                m_threadPoolScheduler           = new IoServiceThreadPoolScheduler(ioService, maxTasksConcurrency);
                m_concurrentAccumulateScheduler = new AccumulateTasksSchedulerDecorator(m_threadPoolScheduler, _ => taskAdded(m_concurrentTaskAdded));
                var strandScheduler           = new StrandSchedulerDecorator(m_threadPoolScheduler);
                var innerStrandProxyScheduler = new ProxyScheduler(strandScheduler);

                m_strandAccumulateScheduler = new AccumulateTasksSchedulerDecorator(strandScheduler, _ => taskAdded(m_exclusiveTaskAdded));
                m_strandProxyScheduler      = new ProxyScheduler(m_strandAccumulateScheduler);
                m_concurrentProxyScheduler  = new ProxyScheduler(m_concurrentAccumulateScheduler);
                m_processTaskLoop           = null;
                m_completedTcs = new TaskCompletionSource <Object>();
                m_stopCts      = new CancellationTokenSource();
                m_isDisposed   = false;
            }
Exemplo n.º 4
0
 public override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
 {
     CheckIfDisposed();
     ProxyScheduler.DoTryExecuteTask(task);
     return(true);
 }
Exemplo n.º 5
0
 public override void QueueTask(Task task)
 {
     CheckIfDisposed();
     ProxyScheduler.DoTryExecuteTask(task);
 }