System.Windows.Forms.Control.BeginInvoke Method

Executes the specified delegate asynchronously on the thread that the control's underlying handle was created on.

Syntax

[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Advanced)]
public IAsyncResult BeginInvoke (Delegate method)

Parameters

method
A delegate to a method that takes no parameters.

Returns

An IAsyncResult that represents the result of the Control.BeginInvoke(Delegate) operation.

Remarks

The delegate is called asynchronously, and this method returns immediately. You can call this method from any thread, even the thread that owns the control's handle. If the control's handle does not exist yet, this method searches up the control's parent chain until it finds a control or form that does have a window handle. If no appropriate handle can be found, Control.BeginInvoke(Delegate) will throw an exception. Exceptions within the delegate method are considered untrapped and will be sent to the application's untrapped exception handler.

You can call Control.EndInvoke(IAsyncResult) to retrieve the return value from the delegate, if neccesary, but this is not required. Control.EndInvoke(IAsyncResult) will block until the return value can be retrieved.

Note:

Most methods on a control can only be called from the thread where the control was created. In addition to the Control.InvokeRequired property, there are four methods on a control that are thread safe: Control.Invoke(Delegate), Control.BeginInvoke(Delegate), Control.EndInvoke(IAsyncResult), and Control.CreateGraphics if the handle for the control has already been created. Calling Control.CreateGraphics before the control's handle has been created on a background thread can cause illegal cross thread calls. For all other method calls, you should use one of the invoke methods to marshal the call to the control's thread. The invoke methods always invoke their callbacks on the control's thread.

Note:

An exception might be thrown if the thread that should process the message is no longer active.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0