示例#1
0
 private void SubmitAndWaitForConnect(List <IThrottleOperation> connectJobOperations)
 {
     using (ThrottleManager manager = new ThrottleManager())
     {
         EventHandler <EventArgs> handler2 = null;
         using (ManualResetEvent connectResult = new ManualResetEvent(false))
         {
             if (handler2 == null)
             {
                 handler2 = (sender, eventArgs) => connectResult.Set();
             }
             EventHandler <EventArgs> handler = handler2;
             manager.ThrottleComplete += handler;
             try
             {
                 manager.ThrottleLimit = 0;
                 manager.SubmitOperations(connectJobOperations);
                 manager.EndSubmitOperations();
                 connectResult.WaitOne();
             }
             finally
             {
                 manager.ThrottleComplete -= handler;
             }
         }
     }
 }
示例#2
0
 internal PSInvokeExpressionSyncJob(
     List <IThrottleOperation> operations,
     ThrottleManager throttleManager)
 {
     this.Results.AddRef();
     this.throttleManager = throttleManager;
     this.RegisterThrottleComplete(this.throttleManager);
     foreach (IThrottleOperation operation in operations)
     {
         ExecutionCmdletHelper helper = operation as ExecutionCmdletHelper;
         if (helper.Pipeline.Runspace is RemoteRunspace runspace && runspace.RunspaceStateInfo.State == RunspaceState.BeforeOpen)
         {
             runspace.URIRedirectionReported += new EventHandler <RemoteDataEventArgs <Uri> >(((PSRemotingChildJob)this).HandleURIDirectionReported);
             runspace.StateChanged           += new EventHandler <RunspaceStateEventArgs>(this.HandleRunspaceStateChanged);
         }
         this.helpers.Add(helper);
         this.AggregateResultsFromHelper(helper);
         RemotePipeline pipeline = helper.Pipeline as RemotePipeline;
         this.powershells.Add(pipeline.PowerShell.InstanceId, pipeline.PowerShell);
     }
     throttleManager.SubmitOperations(operations);
     throttleManager.EndSubmitOperations();
 }