Dispatcher Class Home
This page is specific to:Microsoft Version:3.03.5Silverlight 34.0
.NET Framework Class Library for Silverlight
Dispatcher Class

Provides services for managing the queue of work items for a thread.

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

'Usage

Dim instance As Dispatcher

'Declaration

<CLSCompliantAttribute(True)> _
Public NotInheritable Class Dispatcher
Remarks

The Dispatcher class currently provides support only for running code on the user interface (UI) thread from a non-UI thread.

You can access the Dispatcher object for the UI thread through the DependencyObject..::.Dispatcher and ScriptObject..::.Dispatcher properties. These are instance methods, but instances of these types are frequently inaccessible from non-UI threads. However, the application's Deployment object is a DependencyObject, and it is available on any thread through its Current property.

You can call the CheckAccess method to determine whether the caller is on the UI thread. If the caller is not on the UI thread, you can call BeginInvoke to run the specified delegate on the UI thread.

Examples

The following code example demonstrates how to use this class.

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


Inheritance Hierarchy

System..::.Object
  System.Windows.Threading..::.Dispatcher
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms

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

See Also

Reference

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View