이 설명서는 보관되지만 유지 되지 않습니다.

Dispatcher 클래스

Provides services for managing the queue of work items for a thread. This class cannot be inherited.

네임스페이스: System.Windows.Threading
어셈블리: WindowsBase(windowsbase.dll)

public sealed class Dispatcher
public final class Dispatcher
public final class Dispatcher
이 관리되는 클래스는 XAML에서 사용할 수 없습니다.

The Dispatcher maintains a prioritized queue of work items for a specific thread.

When a Dispatcher is created on a thread, it becomes the only Dispatcher that can be associated with the thread, even if the Dispatcher is shut down.

If you attempt to get the CurrentDispatcher for the current thread and a Dispatcher is not associated with the thread a Dispatcher will be created.

If a Dispatcher is shut down, it cannot be restarted.

In WPF, a DispatcherObject can only be accessed by the Dispatcher it is associated with. For example, a background thread cannot update the contents of a Button that is associated with the Dispatcher on the UI thread. In order for the background thread to access the Content property of the Button, the background thread must delegate the work to the Dispatcher associated with the UI thread. This is accomplished by using either Invoke or BeginInvoke. Invoke is synchronous and BeginInvoke is asynchronous. The operation is added to the queue of the Dispatcher at the specified DispatcherPriority.

If BeginInvoke is called on a Dispatcher which has shut down, the status property of the returned DispatcherOperation is set to Aborted.

All of the methods on Dispatcher, with the exception of DisableProcessing, are free-threaded.

Objects that derive from DispatcherObject have thread affinity.

Objects that derive from Freezable are free-threaded when they are frozen. For more information, see the Freezable Objects Overview.

The following example shows how to place an operation onto a Dispatcher. For the full source code of this example, see the Single Threaded Application With Long Running Calculation sample.

First, a delegate is created that accepts no arguments.

public delegate void NextPrimeDelegate();

Next, BeginInvoke is called. This call to BeginInvoke takes two parameters: the priority, which is set to Normal, and the callback, which is passed in through an instance of the delegate nextPrimeDelegate.

startStopButton.Dispatcher.BeginInvoke(
    DispatcherPriority.Normal,
    new NextPrimeDelegate(CheckNextNumber));

System.Object
  System.Windows.Threading.Dispatcher

이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.

Microsoft .NET Framework 3.0은 Windows Vista, Microsoft Windows XP SP2 및 Windows Server 2003 SP1에서 지원됩니다.

.NET Framework

3.0에서 지원
표시: