共用方式為


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

用來重新啟用發送器處理的結構。

範例

下列範例示範如何停用發送器處理並重新啟用發送器處理。 DisableProcessing在 using 語句中呼叫 。 DisableProcessingDispatcherProcessingDisabled 傳回 結構,當做 using 區塊完成時要處置的物件使用。 在 結構上 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 可用來重新啟用發送器處理。 在 結構上 DispatcherProcessingDisabled 呼叫 Dispose 可重新啟用處理。

DisableProcessing 只能在與 相關聯的執行緒 Dispatcher 上呼叫 。

適用於