Dispatcher..::.PushFrame Method Home
This page is specific to:.NET Framework Version:3.03.54.0
.NET Framework Class Library
Dispatcher..::.PushFrame Method

Enters an execute loop.

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

'Usage

Dim frame As DispatcherFrame

Dispatcher.PushFrame(frame)

'Declaration

<UIPermissionAttribute(SecurityAction.LinkDemand, Unrestricted := True)> _
Public Shared Sub PushFrame ( _
    frame As DispatcherFrame _
)
You cannot use methods in XAML.

Parameters

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

ExceptionCondition
ArgumentNullException

frame is nullNothingnullptra null reference (Nothing in Visual Basic).

InvalidOperationException

HasShutdownFinished is true

-or-

frame is running on a different Dispatcher.

-or-

Dispatcher processing has been disabled.

Remarks

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.

Examples

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 void DoEvents()
{
    DispatcherFrame frame = new DispatcherFrame();
    Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background,
        new DispatcherOperationCallback(ExitFrame), frame);
    Dispatcher.PushFrame(frame);
}

public object ExitFrame(object f)
{
    ((DispatcherFrame)f).Continue = false;

    return null;
}


.NET Framework Security

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Other Resources

Community Content

PushFrame restricted to current thread
Added by:mlippert
According to the Microsoft WPF instructor:
PushFrame() will work only on CurrentThread, even if you call it on a dispatcher that represents a different – non current thread

In other words:
given a dispatcher to a thread that is not the current thread the following won't work as expected because PushFrame expects the frame argument to be associated with the current thread:
DispatcherFrame nestedFrame = new DispatcherFrame();

DispatcherOperation exitOperation = dispatcher.BeginInvoke(priority, _exitFrameCallback, nestedFrame);

// pump the nested message loop, the nested message loop will
// immediately process the messages left inside the message queue.
Dispatcher.PushFrame(nestedFrame);

// If the "exitFrame" callback doesn't get finished, Abort it.
if (exitOperation.Status != DispatcherOperationStatus.Completed)
{
exitOperation.Abort();
}


© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View