Dispatcher.DisableProcessing 方法

定义

禁用对 Dispatcher 队列的处理。

public:
 System::Windows::Threading::DispatcherProcessingDisabled DisableProcessing();
public System.Windows.Threading.DispatcherProcessingDisabled DisableProcessing ();
member this.DisableProcessing : unit -> System.Windows.Threading.DispatcherProcessingDisabled
Public Function DisableProcessing () As DispatcherProcessingDisabled

返回

DispatcherProcessingDisabled

一个用于重新启用调度程序处理的结构。

示例

以下示例演示如何禁用调度程序处理并重新启用调度程序处理。 DisableProcessingusing 语句中调用。 DisableProcessing 返回一个 DispatcherProcessingDisabled 结构,该结构用作 使用 块完成后要释放的对象。 在结构上DispatcherProcessingDisabled调用时Dispose,重新启用调度程序处理。

// The Dispose() method is called at the end of the using statement.
// Calling Dispose on the DispatcherProcessingDisabled structure, 
// which is returned from the call to DisableProcessing, will
// re-enalbe Dispatcher processing.
using (Dispatcher.DisableProcessing())
{
    // Do work while the dispatcher processing is disabled.
    Thread.Sleep(2000);
}
' The Dispose() method is called at the end of the using statement.
' Calling Dispose on the DispatcherProcessingDisabled structure, 
' which is returned from the call to DisableProcessing, will
' re-enable Dispatcher processing.
Using Dispatcher.DisableProcessing()
    ' Do work while the dispatcher processing is disabled.
    Thread.Sleep(2000)
End Using

注解

禁用调度程序处理是一种高级方法,旨在消除不相关的重新进入的可能性。

禁用处理的效果如下:

  • CLR 锁不会在内部泵送消息。

  • DispatcherFrame 不允许推送对象。

  • 不允许消息处理。

DispatcherProcessingDisabled调用时返回的结构DisableProcessing可用于重新启用调度程序处理。 调用DisposeDispatcherProcessingDisabled结构可重新启用处理。

DisableProcessing 只能在与之关联的线程 Dispatcher 上调用。

适用于