Share via


Dispatcher.BeginInvoke Method (Delegate, array<Object[])

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Executes the specified delegate asynchronously with the specified array of arguments on the thread the Dispatcher is associated with.

Namespace:  System.Windows.Threading
Assembly:  System.Windows (in System.Windows.dll)

Syntax

'Declaration
Public Function BeginInvoke ( _
    d As Delegate, _
    ParamArray args As Object() _
) As DispatcherOperation
public DispatcherOperation BeginInvoke(
    Delegate d,
    params Object[] args
)

Parameters

  • d
    Type: System.Delegate
    A delegate to a method that takes multiple arguments, which is pushed onto the Dispatcher event queue.
  • args
    Type: array<System.Object[]
    An array of objects to pass as arguments to the specified method.

Return Value

Type: System.Windows.Threading.DispatcherOperation
An object, which is returned immediately after BeginInvoke is called, that represents the operation that has been posted to the Dispatcher queue.

Examples

The following code example demonstrates how to use this method.

Private Delegate Sub AddTextDelegate(ByVal p As Panel, ByVal text As String)

Private Sub AddText(ByVal p As Panel, ByVal text As String)
    p.Children.Clear()
    Dim t As New TextBlock
    t.Text = text
    p.Children.Add(t)
End Sub

Private Sub TestBeginInvokeWithParameters(ByVal p As Panel)
    If p.Dispatcher.CheckAccess() _
        Then AddText(p, "Added directly.") _
        Else p.Dispatcher.BeginInvoke(New AddTextDelegate( _
            AddressOf AddText), p, "Added by Dispatcher.")
End Sub
private delegate void AddTextDelegate(Panel p, String text);

private void AddText(Panel p, String text)
{
    p.Children.Clear();
    p.Children.Add(new TextBlock { Text = text });
}

private void TestBeginInvokeWithParameters(Panel p)
{
    if (p.Dispatcher.CheckAccess()) AddText(p, "Added directly.");
    else p.Dispatcher.BeginInvoke(
        new AddTextDelegate(AddText), p, "Added by Dispatcher.");
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.