private void CheckIfThrottlingJobIsComplete() { if (_throttlingJob.IsThrottlingJobCompleted) { List <PSDataCollection <PSStreamObject> > resultsToAggregate = new List <PSDataCollection <PSStreamObject> >(); lock (_myLock) { foreach (Job registeredJob in _monitoredJobs) { resultsToAggregate.Add(registeredJob.Results); } foreach (Job throttledJob in _throttlingJob.GetChildJobsSnapshot()) { resultsToAggregate.Add(throttledJob.Results); } resultsToAggregate.Add(_throttlingJob.Results); } foreach (PSDataCollection <PSStreamObject> resultToAggregate in resultsToAggregate) { this.AggregateJobResults(resultToAggregate); } lock (_myLock) { if (!_disposed && !_aggregatedResults.IsAddingCompleted) { _aggregatedResults.CompleteAdding(); } } } }
public static void ForwardAllResultsToCmdlet(ThrottlingJob throttlingJob, Cmdlet cmdlet, CancellationToken?cancellationToken) { using (var helper = new ForwardingHelper(throttlingJob)) { try { throttlingJob.ChildJobAdded += helper.ThrottlingJob_ChildJobAdded; try { throttlingJob.StateChanged += helper.ThrottlingJob_StateChanged; IDisposable cancellationTokenRegistration = null; if (cancellationToken.HasValue) { cancellationTokenRegistration = cancellationToken.Value.Register(helper.CancelForwarding); } try { Interlocked.MemoryBarrier(); ThreadPool.QueueUserWorkItem( delegate { helper.StartMonitoringJob(throttlingJob); foreach (Job childJob in throttlingJob.GetChildJobsSnapshot()) { helper.StartMonitoringJob(childJob); } helper.CheckIfThrottlingJobIsComplete(); }); helper.ForwardResults(cmdlet); } finally { if (cancellationTokenRegistration != null) { cancellationTokenRegistration.Dispose(); } } } finally { throttlingJob.StateChanged -= helper.ThrottlingJob_StateChanged; } } finally { throttlingJob.ChildJobAdded -= helper.ThrottlingJob_ChildJobAdded; } } }
public static void ForwardAllResultsToCmdlet(ThrottlingJob throttlingJob, Cmdlet cmdlet, CancellationToken?cancellationToken) { WaitCallback callBack = null; using (ThrottlingJob.ForwardingHelper helper = new ThrottlingJob.ForwardingHelper(throttlingJob)) { try { throttlingJob.ChildJobAdded += new EventHandler <ThrottlingJobChildAddedEventArgs>(helper.ThrottlingJob_ChildJobAdded); try { throttlingJob.StateChanged += new EventHandler <JobStateEventArgs>(helper.ThrottlingJob_StateChanged); IDisposable disposable = null; if (cancellationToken.HasValue) { disposable = cancellationToken.Value.Register(new Action(helper.CancelForwarding)); } try { Thread.MemoryBarrier(); if (callBack == null) { callBack = delegate(object param0) { helper.StartMonitoringJob(throttlingJob); foreach (Job job in throttlingJob.GetChildJobsSnapshot()) { helper.StartMonitoringJob(job); } helper.CheckIfThrottlingJobIsComplete(); }; } ThreadPool.QueueUserWorkItem(callBack); helper.ForwardResults(cmdlet); } finally { if (disposable != null) { disposable.Dispose(); } } } finally { throttlingJob.StateChanged -= new EventHandler <JobStateEventArgs>(helper.ThrottlingJob_StateChanged); } } finally { throttlingJob.ChildJobAdded -= new EventHandler <ThrottlingJobChildAddedEventArgs>(helper.ThrottlingJob_ChildJobAdded); } } }
public static void ForwardAllResultsToCmdlet(ThrottlingJob throttlingJob, Cmdlet cmdlet, CancellationToken? cancellationToken) { WaitCallback callBack = null; using (ThrottlingJob.ForwardingHelper helper = new ThrottlingJob.ForwardingHelper(throttlingJob)) { try { throttlingJob.ChildJobAdded += new EventHandler<ThrottlingJobChildAddedEventArgs>(helper.ThrottlingJob_ChildJobAdded); try { throttlingJob.StateChanged += new EventHandler<JobStateEventArgs>(helper.ThrottlingJob_StateChanged); IDisposable disposable = null; if (cancellationToken.HasValue) { disposable = cancellationToken.Value.Register(new Action(helper.CancelForwarding)); } try { Thread.MemoryBarrier(); if (callBack == null) { callBack = delegate (object param0) { helper.StartMonitoringJob(throttlingJob); foreach (Job job in throttlingJob.GetChildJobsSnapshot()) { helper.StartMonitoringJob(job); } helper.CheckIfThrottlingJobIsComplete(); }; } ThreadPool.QueueUserWorkItem(callBack); helper.ForwardResults(cmdlet); } finally { if (disposable != null) { disposable.Dispose(); } } } finally { throttlingJob.StateChanged -= new EventHandler<JobStateEventArgs>(helper.ThrottlingJob_StateChanged); } } finally { throttlingJob.ChildJobAdded -= new EventHandler<ThrottlingJobChildAddedEventArgs>(helper.ThrottlingJob_ChildJobAdded); } } }
public static void ForwardAllResultsToCmdlet(ThrottlingJob throttlingJob, Cmdlet cmdlet, CancellationToken? cancellationToken) { using (var helper = new ForwardingHelper(throttlingJob)) { try { throttlingJob.ChildJobAdded += helper.ThrottlingJob_ChildJobAdded; try { throttlingJob.StateChanged += helper.ThrottlingJob_StateChanged; IDisposable cancellationTokenRegistration = null; if (cancellationToken.HasValue) { cancellationTokenRegistration = cancellationToken.Value.Register(helper.CancelForwarding); } try { Interlocked.MemoryBarrier(); ThreadPool.QueueUserWorkItem( delegate { helper.StartMonitoringJob(throttlingJob); foreach (Job childJob in throttlingJob.GetChildJobsSnapshot()) { helper.StartMonitoringJob(childJob); } helper.CheckIfThrottlingJobIsComplete(); }); helper.ForwardResults(cmdlet); } finally { if (cancellationTokenRegistration != null) { cancellationTokenRegistration.Dispose(); } } } finally { throttlingJob.StateChanged -= helper.ThrottlingJob_StateChanged; } } finally { throttlingJob.ChildJobAdded -= helper.ThrottlingJob_ChildJobAdded; } } }