Example #1
0
            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);
                    }
                }
            }
Example #2
0
 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);
         }
     }
 }