Execute() публичный Метод

Execute the current work item, including any child work items.
public Execute ( ) : void
Результат void
Пример #1
0
        /// <summary>
        /// Dispatch a single work item for execution. The first
        /// work item dispatched is saved as the top-level
        /// work item and a thread is created on which to
        /// run it. Subsequent calls come from the top level
        /// item or its descendants on the proper thread.
        /// </summary>
        /// <param name="work">The item to dispatch</param>
        public void Dispatch(WorkItem work)
        {
#if PORTABLE
            if (work != null)
            {
                work.Execute();
            }
#else
            if (_topLevelWorkItem != null)
            {
                work.Execute();
            }
            else
            {
                _topLevelWorkItem = work;
                _runnerThread     = new Thread(RunnerThreadProc);

#if !NETCF && !SILVERLIGHT
                if (work.TargetApartment == ApartmentState.STA)
                {
                    _runnerThread.SetApartmentState(ApartmentState.STA);
                }
#endif

                _runnerThread.Start();
            }
#endif
        }
Пример #2
0
        /// <summary>
        /// Dispatch a single work item for execution. The first
        /// work item dispatched is saved as the top-level
        /// work item and a thread is created on which to
        /// run it. Subsequent calls come from the top level
        /// item or its descendants on the proper thread.
        /// </summary>
        /// <param name="work">The item to dispatch</param>
        public void Dispatch(WorkItem work)
        {
#if PORTABLE || NETSTANDARD1_6
            if (work != null)
            {
                work.Execute();
            }
#else
            if (_topLevelWorkItem != null)
            {
                work.Execute();
            }
            else
            {
                _topLevelWorkItem = work;
                _runnerThread     = new Thread(RunnerThreadProc);

                if (work.TargetApartment == ApartmentState.STA)
                {
                    _runnerThread.SetApartmentState(ApartmentState.STA);
                }

                _runnerThread.Start();
            }
#endif
        }
Пример #3
0
 /// <summary>
 /// Dispatch a single work item for execution by
 /// executing it directly.
 /// <param name="work">The item to dispatch</param>
 /// </summary>
 public void Dispatch(WorkItem work)
 {
     if (work != null)
     {
         work.Execute();
     }
 }
Пример #4
0
        private void TestWorkerThreadProc()
        {
            _running = true;

            try
            {
                while (_running)
                {
                    _currentWorkItem = WorkQueue.Dequeue();
                    if (_currentWorkItem == null)
                    {
                        break;
                    }

                    log.Info("{0} executing {1}", _workerThread.Name, _currentWorkItem.Name);

                    Busy(this, EventArgs.Empty);

                    _currentWorkItem.TestWorker = this;

                    _currentWorkItem.Execute();

                    Idle(this, EventArgs.Empty);

                    ++_workItemCount;
                }
            }
            finally
            {
                log.Info("{0} stopping - {1} WorkItems processed.", Name, _workItemCount);
            }
        }
Пример #5
0
        /// <summary>
        /// Dispatch a single work item for execution. The first
        /// work item dispatched is saved as the top-level
        /// work item and a thread is created on which to
        /// run it. Subsequent calls come from the top level
        /// item or its descendants on the proper thread.
        /// </summary>
        /// <param name="work">The item to dispatch</param>
        public void Dispatch(WorkItem work)
        {
#if PORTABLE
            if (work != null)
                work.Execute();
#else
            if (_topLevelWorkItem != null)
                work.Execute();
            else
            {
                _topLevelWorkItem = work;
                _runnerThread = new Thread(RunnerThreadProc);
                _runnerThread.Start();
            }	
#endif
        }
Пример #6
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;
            }
        }
 /// <summary>
 /// Dispatch a single work item for execution by
 /// executing it directly.
 /// </summary>
 /// <param name="work">The item to dispatch</param>
 public Task Dispatch(WorkItem work)
 {
     if (work != null)
     {
         return(work.Execute());
     }
     return(Task.Delay(0));
 }
Пример #8
0
        /// <summary>
        /// Dispatch a single work item for execution. The first
        /// work item dispatched is saved as the top-level
        /// work item and a thread is created on which to
        /// run it. Subsequent calls come from the top level
        /// item or its descendants on the proper thread.
        /// </summary>
        /// <param name="work">The item to dispatch</param>
        public void Dispatch(WorkItem work)
        {
#if PORTABLE || NETSTANDARD1_6
            if (work != null)
                work.Execute();
#else
            if (_topLevelWorkItem != null)
                work.Execute();
            else
            {
                _topLevelWorkItem = work;
                _runnerThread = new Thread(RunnerThreadProc);

                if (work.TargetApartment == ApartmentState.STA)
                    _runnerThread.SetApartmentState(ApartmentState.STA);

                _runnerThread.Start();
            }
#endif
        }
Пример #9
0
        /// <summary>
        /// Dispatch a single work item for execution. The first
        /// work item dispatched is saved as the top-level
        /// work item and a thread is created on which to
        /// run it. Subsequent calls come from the top level
        /// item or its descendants on the proper thread.
        /// </summary>
        /// <param name="work">The item to dispatch</param>
        public void Dispatch(WorkItem work)
        {
#if PORTABLE
            if (work != null)
            {
                work.Execute();
            }
#else
            if (_topLevelWorkItem != null)
            {
                work.Execute();
            }
            else
            {
                _topLevelWorkItem = work;
                _runnerThread     = new Thread(RunnerThreadProc);
                _runnerThread.Start();
            }
#endif
        }
 /// <summary>
 /// Dispatch a single work item for execution. The first
 /// work item dispatched is saved as the top-level
 /// work item and a thread is created on which to
 /// run it. Subsequent calls come from the top level
 /// item or its descendants on the proper thread.
 /// </summary>
 /// <param name="work">The item to dispatch</param>
 public void Dispatch(WorkItem work)
 {
     if (_topLevelWorkItem != null)
         work.Execute();
     else
     {
         _topLevelWorkItem = work;
         _runnerThread = new Thread(RunnerThreadProc);
         _runnerThread.Start();
     }
 }
Пример #11
0
        /// <summary>
        /// Dispatch a single work item for execution. The first
        /// work item dispatched is saved as the top-level
        /// work item and a thread is created on which to
        /// run it. Subsequent calls come from the top level
        /// item or its descendants on the proper thread.
        /// </summary>
        /// <param name="work">The item to dispatch</param>
        public void Dispatch(WorkItem work)
        {
#if PORTABLE
            if (work != null)
                work.Execute();
#else
            if (_topLevelWorkItem != null)
                work.Execute();
            else
            {
                _topLevelWorkItem = work;
                _runnerThread = new Thread(RunnerThreadProc);

#if !NETCF && !SILVERLIGHT
                if (work.TargetApartment == ApartmentState.STA)
                    _runnerThread.SetApartmentState(ApartmentState.STA);
#endif

                _runnerThread.Start();
            }
#endif
        }
Пример #12
0
 /// <summary>
 /// Dispatch a single work item for execution. The first
 /// work item dispatched is saved as the top-level
 /// work item and a thread is created on which to
 /// run it. Subsequent calls come from the top level
 /// item or its descendants on the proper thread.
 /// </summary>
 /// <param name="work">The item to dispatch</param>
 public void Dispatch(WorkItem work)
 {
     if (_topLevelWorkItem != null)
     {
         work.Execute();
     }
     else
     {
         _topLevelWorkItem = work;
         _runnerThread     = new Thread(RunnerThreadProc);
         _runnerThread.Start();
     }
 }
Пример #13
0
        // 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;
            }
        }
Пример #14
0
        private async Task TestWorkerThreadProc()
        {
            _running = true;

            try
            {
                while (_running)
                {
                    _currentWorkItem = WorkQueue.Dequeue();
                    if (_currentWorkItem == null)
                    {
                        break;
                    }

                    log.Info("{0} executing {1}", _workerThread.Name, _currentWorkItem.Name);

                    _currentWorkItem.TestWorker = this;

                    // During this Busy call, the queue state may be saved.
                    // This gives us a new set of queues, which are initially
                    // empty. The intention is that only children of the current
                    // executing item should make use of the new set of queues.
                    // TODO: If we had a separate NonParallelTestWorker, it
                    // could simply create the isolated queue without any
                    // worrying about competing workers.
                    Busy(this, _currentWorkItem);

                    // Because we execute the current item AFTER the queue state
                    // is saved, its children end up in the new queue set.
                    await _currentWorkItem.Execute();

                    // This call may result in the queues being restored. There
                    // is a potential race condition here. We should not restore
                    // the queues unless all child items have finished.
                    Idle(this, _currentWorkItem);

                    ++_workItemCount;
                }
            }
            finally
            {
                log.Info("{0} stopping - {1} WorkItems processed.", Name, _workItemCount);
            }
        }
Пример #15
0
        private void TestWorkerThreadProc()
        {
            log.Info("{0} starting ", _workerThread.Name);

            _running = true;

            try
            {
                while (_running)
                {
                    _currentWorkItem = _readyQueue.Dequeue();
                    if (_currentWorkItem == null)
                    {
                        break;
                    }

                    log.Info("{0} executing {1}", _workerThread.Name, _currentWorkItem.Test.Name);

                    if (Busy != null)
                    {
                        Busy(this, EventArgs.Empty);
                    }

                    _currentWorkItem.WorkerId = Name;
                    _currentWorkItem.Execute();

                    if (Idle != null)
                    {
                        Idle(this, EventArgs.Empty);
                    }

                    ++_workItemCount;
                }
            }
            finally
            {
                log.Info("{0} stopping - {1} WorkItems processed.", _workerThread.Name, _workItemCount);
            }
        }
Пример #16
0
        private void TestWorkerThreadProc()
        {
            log.Info("{0} starting ", _workerThread.Name);

            _running = true;

            try
            {
                while (_running)
                {
                    _currentWorkItem = _readyQueue.Dequeue();
                    if (_currentWorkItem == null)
                        break;

                    log.Info("{0} executing {1}", _workerThread.Name, _currentWorkItem.Test.Name);

                    if (Busy != null)
                        Busy(this, EventArgs.Empty);

                    _currentWorkItem.WorkerId = Name;
                    _currentWorkItem.Execute();

                    if (Idle != null)
                        Idle(this, EventArgs.Empty);

                    ++_workItemCount;
                }
            }
            finally
            {
                log.Info("{0} stopping - {1} WorkItems processed.", _workerThread.Name, _workItemCount);
            }
        }
Пример #17
0
 private void RunnerThreadProc()
 {
     _topLevelWorkItem.Execute();
 }
Пример #18
0
 private Task RunnerThreadProc()
 {
     return(_topLevelWorkItem.Execute());
 }
Пример #19
0
 private void Execute(WorkItem work)
 {
     log.Debug("Directly executing {0}", work.Test.Name);
     work.Execute();
 }
Пример #20
0
        public static ITestResult ExecuteWorkItem(WorkItem work)
        {
            work.Execute();

            // TODO: Replace with an event - but not while method is static
            while (work.State != WorkItemState.Complete)
            {
#if PORTABLE
                System.Threading.Tasks.Task.Delay(1);
#else
                Thread.Sleep(1);
#endif
            }

            return work.Result;
        }
Пример #21
0
 public void Dispatch(WorkItem work)
 {
     work.Execute();
 }
 private void Execute(WorkItem work)
 {
     log.Debug("Directly executing {0}", work.Test.Name);
     work.Execute();
 }