Exemplo n.º 1
0
        private void CloseOrDisconnectAllRemoteRunspaces(Func <List <RemoteRunspace> > getRunspaces)
        {
            List <RemoteRunspace> list = getRunspaces();

            if (list.Count != 0)
            {
                EventHandler <EventArgs> handler = null;
                using (ManualResetEvent remoteRunspaceCloseCompleted = new ManualResetEvent(false))
                {
                    ThrottleManager manager = new ThrottleManager();
                    if (handler == null)
                    {
                        handler = (sender, e) => remoteRunspaceCloseCompleted.Set();
                    }
                    manager.ThrottleComplete += handler;
                    foreach (RemoteRunspace runspace in list)
                    {
                        IThrottleOperation operation = new CloseOrDisconnectRunspaceOperationHelper(runspace);
                        manager.AddOperation(operation);
                    }
                    manager.EndSubmitOperations();
                    remoteRunspaceCloseCompleted.WaitOne();
                }
            }
        }
Exemplo n.º 2
0
 private void CloseOrDisconnectAllRemoteRunspaces(Func<List<RemoteRunspace>> getRunspaces)
 {
     List<RemoteRunspace> list = getRunspaces();
     if (list.Count != 0)
     {
         EventHandler<EventArgs> handler = null;
         using (ManualResetEvent remoteRunspaceCloseCompleted = new ManualResetEvent(false))
         {
             ThrottleManager manager = new ThrottleManager();
             if (handler == null)
             {
                 handler = (sender, e) => remoteRunspaceCloseCompleted.Set();
             }
             manager.ThrottleComplete += handler;
             foreach (RemoteRunspace runspace in list)
             {
                 IThrottleOperation operation = new CloseOrDisconnectRunspaceOperationHelper(runspace);
                 manager.AddOperation(operation);
             }
             manager.EndSubmitOperations();
             remoteRunspaceCloseCompleted.WaitOne();
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Closes or disconnects all the remote runspaces passed in by the getRunspace
        /// function.  If a remote runspace supports disconnect then it will be disconnected 
        /// rather than closed.
        /// </summary>
        private void CloseOrDisconnectAllRemoteRunspaces(Func<List<RemoteRunspace>> getRunspaces)
        {
            List<RemoteRunspace> runspaces = getRunspaces();
            if (runspaces.Count == 0) { return; }

            // whether the close of all remoterunspaces completed
            using (ManualResetEvent remoteRunspaceCloseCompleted = new ManualResetEvent(false))
            {
                ThrottleManager throttleManager = new ThrottleManager();
                throttleManager.ThrottleComplete += delegate (object sender, EventArgs e)
                {
                    remoteRunspaceCloseCompleted.Set();
                };

                foreach (RemoteRunspace remoteRunspace in runspaces)
                {
                    IThrottleOperation operation = new CloseOrDisconnectRunspaceOperationHelper(remoteRunspace);
                    throttleManager.AddOperation(operation);
                }
                throttleManager.EndSubmitOperations();

                remoteRunspaceCloseCompleted.WaitOne();
            }
        }