Sdílet prostřednictvím


PowerShell.BeginInvoke Method

Definition

Overloads

BeginInvoke()

Invoke the Command asynchronously. Use EndInvoke() to obtain the output of the command.

BeginInvoke<T>(PSDataCollection<T>, PSInvocationSettings, AsyncCallback, Object)

Invoke the Command asynchronously. Use EndInvoke() to obtain the output of the command.

BeginInvoke<T>(PSDataCollection<T>)

Invoke the Command asynchronously. Use EndInvoke() to obtain the output of the command.

BeginInvoke<TInput,TOutput>(PSDataCollection<TInput>, PSDataCollection<TOutput>)

Invoke the Command asynchronously. When this method is used EndInvoke() returns a null buffer.

BeginInvoke<TInput,TOutput>(PSDataCollection<TInput>, PSDataCollection<TOutput>, PSInvocationSettings, AsyncCallback, Object)

Invoke the Command asynchronously and collect output data into the buffer output. When this method is used EndInvoke() returns a null buffer.

BeginInvoke()

Invoke the Command asynchronously. Use EndInvoke() to obtain the output of the command.

public:
 IAsyncResult ^ BeginInvoke();
public IAsyncResult BeginInvoke ();
member this.BeginInvoke : unit -> IAsyncResult
Public Function BeginInvoke () As IAsyncResult

Returns

Exceptions

Cannot perform the operation because the command is already started. Stop the command and try the operation again. (or) No command is added.

Object is disposed.

Applies to

BeginInvoke<T>(PSDataCollection<T>, PSInvocationSettings, AsyncCallback, Object)

Invoke the Command asynchronously. Use EndInvoke() to obtain the output of the command.

public:
generic <typename T>
 IAsyncResult ^ BeginInvoke(System::Management::Automation::PSDataCollection<T> ^ input, System::Management::Automation::PSInvocationSettings ^ settings, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginInvoke<T> (System.Management.Automation.PSDataCollection<T> input, System.Management.Automation.PSInvocationSettings settings, AsyncCallback callback, object state);
member this.BeginInvoke : System.Management.Automation.PSDataCollection<'T> * System.Management.Automation.PSInvocationSettings * AsyncCallback * obj -> IAsyncResult
Public Function BeginInvoke(Of T) (input As PSDataCollection(Of T), settings As PSInvocationSettings, callback As AsyncCallback, state As Object) As IAsyncResult

Type Parameters

T

Type of the input buffer

Parameters

input
PSDataCollection<T>

Input to the command. See remarks for more details.

settings
PSInvocationSettings

Invocation Settings.

callback
AsyncCallback

An AsyncCallback to call once the BeginInvoke completes. Note: when using this API in script, don't pass in a delegate that is cast from a script block. The callback could be invoked from a thread without a default Runspace and a delegate cast from a script block would fail in that case.

state
Object

A user supplied state to call the callback with.

Returns

Exceptions

Cannot perform the operation because the command is already started. Stop the command and try the operation again. (or) No command is added.

Object is disposed.

Remarks

When invoked using BeginInvoke, invocation doesn't finish until Input is closed. Caller of BeginInvoke must close the input buffer after all input has been written to input buffer. Input buffer is closed by calling Close() method.

If you want this command to execute as a standalone cmdlet (that is, using command-line parameters only), be sure to call Close() before calling BeginInvoke(). Otherwise, the command will be executed as though it had external input. If you observe that the command isn't doing anything, this may be the reason.

Applies to

BeginInvoke<T>(PSDataCollection<T>)

Invoke the Command asynchronously. Use EndInvoke() to obtain the output of the command.

public:
generic <typename T>
 IAsyncResult ^ BeginInvoke(System::Management::Automation::PSDataCollection<T> ^ input);
public IAsyncResult BeginInvoke<T> (System.Management.Automation.PSDataCollection<T> input);
member this.BeginInvoke : System.Management.Automation.PSDataCollection<'T> -> IAsyncResult
Public Function BeginInvoke(Of T) (input As PSDataCollection(Of T)) As IAsyncResult

Type Parameters

T

Type of the input buffer

Parameters

input
PSDataCollection<T>

Input to the command. See remarks for more details.

Returns

Exceptions

Cannot perform the operation because the command is already started. Stop the command and try the operation again. (or) No command is added.

Object is disposed.

Remarks

When invoked using BeginInvoke, invocation doesn't finish until Input is closed. Caller of BeginInvoke must close the input buffer after all input has been written to input buffer. Input buffer is closed by calling Close() method.

If you want this command to execute as a standalone cmdlet (that is, using command-line parameters only), be sure to call Close() before calling BeginInvoke(). Otherwise, the command will be executed as though it had external input. If you observe that the command isn't doing anything, this may be the reason.

Applies to

BeginInvoke<TInput,TOutput>(PSDataCollection<TInput>, PSDataCollection<TOutput>)

Invoke the Command asynchronously. When this method is used EndInvoke() returns a null buffer.

public:
generic <typename TInput, typename TOutput>
 IAsyncResult ^ BeginInvoke(System::Management::Automation::PSDataCollection<TInput> ^ input, System::Management::Automation::PSDataCollection<TOutput> ^ output);
public IAsyncResult BeginInvoke<TInput,TOutput> (System.Management.Automation.PSDataCollection<TInput> input, System.Management.Automation.PSDataCollection<TOutput> output);
member this.BeginInvoke : System.Management.Automation.PSDataCollection<'Input> * System.Management.Automation.PSDataCollection<'Output> -> IAsyncResult
Public Function BeginInvoke(Of TInput, TOutput) (input As PSDataCollection(Of TInput), output As PSDataCollection(Of TOutput)) As IAsyncResult

Type Parameters

TInput

Type of input object(s) for the command invocation.

TOutput

Type of output object(s) expected from the command invocation.

Parameters

input
PSDataCollection<TInput>

Input to the command. See remarks for more details.

output
PSDataCollection<TOutput>

A buffer supplied by the user where output is collected.

Returns

Exceptions

Cannot perform the operation because the command is already started. Stop the command and try the operation again. (or) No command is added.

Object is disposed.

Remarks

When invoked using BeginInvoke, invocation doesn't finish until Input is closed. Caller of BeginInvoke must close the input buffer after all input has been written to input buffer. Input buffer is closed by calling Close() method.

If you want this command to execute as a standalone cmdlet (that is, using command-line parameters only), be sure to call Close() before calling BeginInvoke(). Otherwise, the command will be executed as though it had external input. If you observe that the command isn't doing anything, this may be the reason.

Applies to

BeginInvoke<TInput,TOutput>(PSDataCollection<TInput>, PSDataCollection<TOutput>, PSInvocationSettings, AsyncCallback, Object)

Invoke the Command asynchronously and collect output data into the buffer output. When this method is used EndInvoke() returns a null buffer.

public:
generic <typename TInput, typename TOutput>
 IAsyncResult ^ BeginInvoke(System::Management::Automation::PSDataCollection<TInput> ^ input, System::Management::Automation::PSDataCollection<TOutput> ^ output, System::Management::Automation::PSInvocationSettings ^ settings, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginInvoke<TInput,TOutput> (System.Management.Automation.PSDataCollection<TInput> input, System.Management.Automation.PSDataCollection<TOutput> output, System.Management.Automation.PSInvocationSettings settings, AsyncCallback callback, object state);
member this.BeginInvoke : System.Management.Automation.PSDataCollection<'Input> * System.Management.Automation.PSDataCollection<'Output> * System.Management.Automation.PSInvocationSettings * AsyncCallback * obj -> IAsyncResult
Public Function BeginInvoke(Of TInput, TOutput) (input As PSDataCollection(Of TInput), output As PSDataCollection(Of TOutput), settings As PSInvocationSettings, callback As AsyncCallback, state As Object) As IAsyncResult

Type Parameters

TInput

Type of input object(s) for the command invocation.

TOutput

Type of output object(s) expected from the command invocation.

Parameters

input
PSDataCollection<TInput>

Input to the command. See remarks for more details.

output
PSDataCollection<TOutput>

A buffer supplied by the user where output is collected.

settings
PSInvocationSettings

Invocation Settings.

callback
AsyncCallback

An AsyncCallback to call once the BeginInvoke completes. Note: when using this API in script, don't pass in a delegate that is cast from a script block. The callback could be invoked from a thread without a default Runspace and a delegate cast from a script block would fail in that case.

state
Object

A user supplied state to call the callback with.

Returns

Exceptions

Cannot perform the operation because the command is already started. Stop the command and try the operation again. (or) No command is added.

Object is disposed.

Remarks

When invoked using BeginInvoke, invocation doesn't finish until Input is closed. Caller of BeginInvoke must close the input buffer after all input has been written to input buffer. Input buffer is closed by calling Close() method.

If you want this command to execute as a standalone cmdlet (that is, using command-line parameters only), be sure to call Close() before calling BeginInvoke(). Otherwise, the command will be executed as though it had external input. If you observe that the command isn't doing anything, this may be the reason.

Applies to