Export (0) Print
Expand All

Dispatcher.DisableProcessing Method

Disables processing of the Dispatcher queue.

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

'Declaration
Public Function DisableProcessing As DispatcherProcessingDisabled

Return Value

Type: System.Windows.Threading.DispatcherProcessingDisabled
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 that 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-enable Dispatcher processing.
			Using Dispatcher.DisableProcessing()
				' Do work while the dispatcher processing is disabled.
				Thread.Sleep(2000)
			End Using

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft