private ForwardingHelper(ThrottlingJob throttlingJob) { this._throttlingJob = throttlingJob; this._myLock = new object(); this._monitoredJobs = new HashSet <Job>(); this._aggregatedResults = new BlockingCollection <PSStreamObject>(); }
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); } } }
private ForwardingHelper(ThrottlingJob throttlingJob) { this._throttlingJob = throttlingJob; this._myLock = new object(); this._monitoredJobs = new HashSet<Job>(); this._aggregatedResults = new BlockingCollection<PSStreamObject>(); }
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; } } }