public IAsyncResult BeginExecute(string command, Dictionary<string, object> parameters, ExecutionOptions options,
                                         AsyncCallback callback, object asyncState)
        {
            AsyncCommandResult asyncCommandResult = new AsyncCommandResult(command, parameters, options, callback,
                                                                           asyncState);
            Queue.Enqueue(asyncCommandResult);

            return asyncCommandResult;
        }
        public IAsyncResult BeginExecute(string command, Dictionary <string, object> parameters, ExecutionOptions options,
                                         AsyncCallback callback, object asyncState)
        {
            AsyncCommandResult asyncCommandResult = new AsyncCommandResult(command, parameters, options, callback,
                                                                           asyncState);

            Queue.Enqueue(asyncCommandResult);

            return(asyncCommandResult);
        }
        public Collection <PSObject> EndExecute(IAsyncResult ar)
        {
            AsyncCommandResult asyncCommandResult = ar as AsyncCommandResult;

            if (null == asyncCommandResult)
            {
                throw new InvalidOperationException("the IAsyncResult provided is not of the appropriate type");
            }

            while (!asyncCommandResult.IsCompleted)
            {
                asyncCommandResult.AsyncWaitHandle.WaitOne(100);
                DoWait();
            }
            return(asyncCommandResult.GetCommandResults());
        }
 private void ExecuteQueuedCommand(AsyncCommandResult asynResult)
 {
     Collection<PSObject> results = null;
     try
     {
         IEnumerable<ErrorRecord> error = null;
         results = _executor.ExecuteCommand(asynResult.Command, asynResult.Parameters, out error,
                                            asynResult.ExecutionOptions);
         asynResult.SetComplete(results, false, null);
     }
     catch (Exception e)
     {
         asynResult.SetComplete(results, false, e);
     }
 }