InvokeBegin() public method

Invokes the begin script, if any, sets the pipeline script once, returns the begin output.
public InvokeBegin ( string begin, string script ) : Collection
begin string
script string
return Collection
        /// <summary>
        /// Gets the next part of input items and feeds them to a ready job.
        /// If forced waits for a ready job.
        /// </summary>
        void Feed(bool force)
        {
            // try to make more jobs ready and more input available on Refill
            Take();

            // no input? check this after taking, Refill adds input on taking
            if (_queue.Count == 0)
            {
                return;
            }

            // all busy?
            if (_Count - _work.Count == 0)
            {
                // no ready jobs, done if not forced
                if (!force)
                {
                    return;
                }

                // wait for jobs and make them ready
                Wait();
                Take();
            }

            // split the queue equally between all potential jobs
            int load = _queue.Count / _Count;

            if (load * _Count < _queue.Count)
            {
                ++load;
            }

            // check limits
            if (load < MinLoad)
            {
                load = MinLoad;
            }
            else if (load > MaxLoad)
            {
                load = MaxLoad;
            }

            lock (_syncObject)
            {
                int nReadyJobs = _Count - _work.Count;
                if (xStop || nReadyJobs == 0)
                {
                    return;
                }

                do
                {
                    // limit load by the queue
                    if (load > _queue.Count)
                    {
                        load = _queue.Count;

                        // if load is less than minimum and not forced then exit
                        if (load < MinLoad && !force)
                        {
                            return;
                        }
                    }

                    // next job node
                    LinkedListNode <Job> node = _done.First;
                    if (node == null)
                    {
                        // v1.4.2 Runspaces use the same host as the cmdlet.
                        var job = new Job(RunspaceFactory.CreateRunspace(Host, _iss));
                        node = new LinkedListNode <Job>(job);
                        _work.AddLast(node);
                        WriteResults(job, job.InvokeBegin(_Begin, _Script));
                    }
                    else
                    {
                        _done.RemoveFirst();
                        _work.AddLast(node);
                    }

                    if (xStop)
                    {
                        return;
                    }

                    // feed the job
                    ++_infoPartCount;
                    node.Value.BeginInvoke(_queue, load);

                    // show feed info
                    if (_verbose)
                    {
                        WriteVerbose(string.Format(null, "Split-Pipeline: Jobs = {0}; Load = {1}; Queue = {2}", _work.Count, load, _queue.Count));
                    }
                }while (!xStop && --nReadyJobs > 0 && _queue.Count > 0);
            }
        }
        /// <summary>
        /// Gets the next part of input items and feeds them to a ready job.
        /// If forced waits for a ready job.
        /// </summary>
        void Feed(bool force)
        {
            // try to make more jobs ready and more input available on Refill
            Take();

            // no input? check this after taking, Refill adds input on taking
            if (_queue.Count == 0)
                return;

            // all busy?
            if (_Count - _work.Count == 0)
            {
                // no ready jobs, done if not forced
                if (!force)
                    return;

                // wait for jobs and make them ready
                Wait();
                Take();
            }

            // split the queue equally between all potential jobs
            int load = _queue.Count / _Count;
            if (load * _Count < _queue.Count)
                ++load;

            // check limits
            if (load < MinLoad)
                load = MinLoad;
            else if (load > MaxLoad)
                load = MaxLoad;

            lock (_syncObject)
            {
                int nReadyJobs = _Count - _work.Count;
                if (xStop || nReadyJobs == 0)
                    return;

                do
                {
                    // limit load by the queue
                    if (load > _queue.Count)
                    {
                        load = _queue.Count;

                        // if load is less than minimum and not forced then exit
                        if (load < MinLoad && !force)
                            return;
                    }

                    // next job node
                    LinkedListNode<Job> node = _done.First;
                    if (node == null)
                    {
                        // v1.4.2 Runspaces use the same host as the cmdlet.
                        var job = new Job(RunspaceFactory.CreateRunspace(Host, _iss));
                        node = new LinkedListNode<Job>(job);
                        _work.AddLast(node);
                        WriteResults(job, job.InvokeBegin(_Begin, _Script));
                    }
                    else
                    {
                        _done.RemoveFirst();
                        _work.AddLast(node);
                    }

                    if (xStop)
                        return;

                    // feed the job
                    ++_infoPartCount;
                    node.Value.BeginInvoke(_queue, load);

                    // show feed info
                    if (_verbose)
                        WriteVerbose(string.Format(null, "Split-Pipeline: Jobs = {0}; Load = {1}; Queue = {2}", _work.Count, load, _queue.Count));
                }
                while (!xStop && --nReadyJobs > 0 && _queue.Count > 0);
            }
        }