示例#1
0
        /// <summary>
        /// EnqueueJob
        /// </summary>
        /// <param name="job"></param>
        /// <param name="throttleLimit"></param>
        public void EnqueueJob(ThreadJob job, int throttleLimit)
        {
            if (job == null)
            {
                throw new ArgumentNullException("job");
            }

            ThrottleLimit     = throttleLimit;
            job.StateChanged += new EventHandler <JobStateEventArgs>(HandleJobStateChanged);

            lock (_syncObject)
            {
                _jobQueue.Enqueue(job);

                if (_haveRunningJobs)
                {
                    return;
                }

                if (_jobQueue.Count > 0)
                {
                    _haveRunningJobs = true;
                    System.Threading.ThreadPool.QueueUserWorkItem(new WaitCallback(ServiceJobs));
                }
            }
        }
示例#2
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            if (!_processFirstRecord)
            {
                if (StreamingHost != null)
                {
                    _threadJob = new ThreadJob(Name, _command, ScriptBlock, FilePath, InitializationScript, ArgumentList,
                                               InputObject, this, StreamingHost);
                }
                else
                {
                    _threadJob = new ThreadJob(Name, _command, ScriptBlock, FilePath, InitializationScript, ArgumentList,
                                               InputObject, this);
                }

                ThreadJob.StartJob(_threadJob, ThrottleLimit);
                WriteObject(_threadJob);

                _processFirstRecord = true;
            }
            else
            {
                // Inject input.
                if (InputObject != null)
                {
                    _threadJob.InjectInput(InputObject);
                }
            }
        }
示例#3
0
        private void HandleJobStateChanged(object sender, JobStateEventArgs e)
        {
            ThreadJob job   = sender as ThreadJob;
            JobState  state = e.JobStateInfo.State;

            if (state == JobState.Completed ||
                state == JobState.Stopped ||
                state == JobState.Failed)
            {
                job.StateChanged -= new EventHandler <JobStateEventArgs>(HandleJobStateChanged);
                DecrementCurrentJobs();
            }
        }
示例#4
0
 /// <summary>
 /// StartJob
 /// </summary>
 /// <param name="job"></param>
 /// <param name="throttleLimit"></param>
 public static void StartJob(ThreadJob job, int throttleLimit)
 {
     s_JobQueue.EnqueueJob(job, throttleLimit);
 }