private void Enqueue(WorkItem work)
        {
            log.Debug("Enqueuing {0}", work.Test.Name);

            if (work.IsParallelizable)
            {
#if !NETCF
                if (work.TargetApartment == ApartmentState.STA)
                {
                    ParallelSTAQueue.Enqueue(work);
                }
                else
#endif
                ParallelQueue.Enqueue(work);
            }
#if !NETCF
            else if (work.TargetApartment == ApartmentState.STA)
            {
                NonParallelSTAQueue.Enqueue(work);
            }
#endif
            else
            {
                NonParallelQueue.Enqueue(work);
            }
        }
Esempio n. 2
0
        private void Dispatch(WorkItem work, ExecutionStrategy strategy)
        {
            log.Debug("Using {0} strategy for {1}", strategy, work.Name);

            switch (strategy)
            {
            default:
            case ExecutionStrategy.Direct:
                work.Execute();
                break;

            case ExecutionStrategy.Parallel:
                if (work.TargetApartment == ApartmentState.STA)
                {
                    ParallelSTAQueue.Enqueue(work);
                }
                else
                {
                    ParallelQueue.Enqueue(work);
                }
                break;

            case ExecutionStrategy.NonParallel:
                if (work.TargetApartment == ApartmentState.STA)
                {
                    NonParallelSTAQueue.Enqueue(work);
                }
                else
                {
                    NonParallelQueue.Enqueue(work);
                }
                break;
            }
        }
        // Separate method so it can be used by Start
        private async Task Dispatch(WorkItem work, ParallelExecutionStrategy strategy)
        {
            log.Debug("Using {0} strategy for {1}", strategy, work.Name);

            // Currently, we only track CompositeWorkItems - this could be expanded
            var composite = work as CompositeWorkItem;

            if (composite != null)
            {
                lock (_activeWorkItems)
                {
                    _activeWorkItems.Add(composite);
                    composite.Completed += OnWorkItemCompletion;
                }
            }

            switch (strategy)
            {
            default:
            case ParallelExecutionStrategy.Direct:
                await work.Execute();

                break;

            case ParallelExecutionStrategy.Parallel:
                if (work.TargetApartment == ApartmentState.STA)
                {
                    ParallelSTAQueue.Enqueue(work);
                }
                else
                {
                    ParallelQueue.Enqueue(work);
                }
                break;

            case ParallelExecutionStrategy.NonParallel:
                if (work.TargetApartment == ApartmentState.STA)
                {
                    NonParallelSTAQueue.Enqueue(work);
                }
                else
                {
                    NonParallelQueue.Enqueue(work);
                }
                break;
            }
        }