Пример #1
0
        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);
            }
        }
Пример #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;
            }
        }
Пример #3
0
        // Separate method so it can be used by Start
        private void 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:
                work.Execute();
                break;

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

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