Dispatcher.PushFrame Method

Enters an execute loop.

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

'Declaration
<UIPermissionAttribute(SecurityAction.LinkDemand, Unrestricted := True)> _
Public Shared Sub PushFrame ( _
	frame As DispatcherFrame _
)

Parameters

frame
Type: System.Windows.Threading.DispatcherFrame
The frame for the dispatcher to process.

ExceptionCondition
ArgumentNullException

frame is Nothing.

InvalidOperationException

HasShutdownFinished is true

-or-

frame is running on a different Dispatcher.

-or-

Dispatcher processing has been disabled.

A DispatcherFrame represents a loop that processes pending work items.

The Dispatcher processes the work item queue in a loop. The loop is referred to as a frame. The initial loop is typically initiated by the application by calling Run.

PushFrame enters a loop represented by the parameter frame. At each iteration of the loop, the Dispatcher will check the Continue property on the DispatcherFrame class to determine whether the loop should continue or if it should stop.

DispatcherFrame allows for the Continue property to be set explicitly and it respects the HasShutdownStarted property on the Dispatcher. This means when the Dispatcher starts to shut down, frames that use the default DispatcherFrame implementation will exit, which enables all nested frames to exit.

The following example shows how to use a DispatcherFrame to achieve similar results as the Windows Forms DoEvents method.


		<SecurityPermissionAttribute(SecurityAction.Demand, Flags := SecurityPermissionFlag.UnmanagedCode)>
		Public Sub DoEvents()
			Dim frame As New DispatcherFrame()
			Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, New DispatcherOperationCallback(AddressOf ExitFrame), frame)
			Dispatcher.PushFrame(frame)
		End Sub

		Public Function ExitFrame(ByVal f As Object) As Object
			CType(f, DispatcherFrame).Continue = False

			Return Nothing
		End Function


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft