Windows apps
Collapse the table of content
Expand the table of content
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.PushFrame Method (DispatcherFrame)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Enters an execute loop.

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

[SecurityCriticalAttribute]
[UIPermissionAttribute(SecurityAction.LinkDemand, Unrestricted = true)]
public static void PushFrame(
	DispatcherFrame frame
)

Parameters

frame
Type: System.Windows.Threading.DispatcherFrame

The frame for the dispatcher to process.

Exception Condition
ArgumentNullException

frame is null.

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

UIPermission

for pushing an execution frame. Associated enumerations: PermissionState.Unrestricted

.NET Framework
Available since 3.0
Return to top
Show:
© 2017 Microsoft