Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Dispatcher.DisableProcessing Method

Disables processing of the Dispatcher queue.

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

public DispatcherProcessingDisabled DisableProcessing ()
public DispatcherProcessingDisabled DisableProcessing ()
public function DisableProcessing () : DispatcherProcessingDisabled
You cannot use methods in XAML.

Return Value

A structure used to re-enable dispatcher processing.

Disabling dispatcher processing is an advanced method that is intended to eliminate the chance of unrelated reentrancy.

The effects of disabling processing are as follows:

  • CLR locks will not pump messages internally.

  • DispatcherFrame objects are not allowed to be pushed.

  • Message processing is not permitted.

The DispatcherProcessingDisabled structure that DisableProcessing returns when it is called can be used to re-enable dispatcher processing. Calling Dispose on the DispatcherProcessingDisabled structure re-enables processing.

DisableProcessing can only be called on the thread the Dispatcher is associated with.

The following example shows how to disable dispatcher processing and re-enable dispatcher processing. DisableProcessing is called in a using statement. DisableProcessing returns a DispatcherProcessingDisabled structure which is used as the object to be disposed when the using block finishes. When Dispose is called on the DispatcherProcessingDisabled structure, dispatcher processing is re-enabled.

// 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);
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2015 Microsoft