Dispatcher.PushFrame(DispatcherFrame) 方法

定義

會進入執行迴圈。

public:
 static void PushFrame(System::Windows::Threading::DispatcherFrame ^ frame);
[System.Security.SecurityCritical]
public static void PushFrame (System.Windows.Threading.DispatcherFrame frame);
public static void PushFrame (System.Windows.Threading.DispatcherFrame frame);
[<System.Security.SecurityCritical>]
static member PushFrame : System.Windows.Threading.DispatcherFrame -> unit
static member PushFrame : System.Windows.Threading.DispatcherFrame -> unit
Public Shared Sub PushFrame (frame As DispatcherFrame)

參數

frame
DispatcherFrame

要處理的發送器框架。

屬性

例外狀況

framenull

HasShutdownFinishedtrue

-或- frame 是在不同的 Dispatcher 上執行。

-或- 已經停用發送器處理。

範例

下列範例示範如何使用 DispatcherFrame 來達成類似Windows Forms DoEvents 方法的結果。

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

備註

DispatcherFrame表示處理暫止工作專案的迴圈。

發送器會在迴圈中處理工作專案佇列。 迴圈稱為框架。 初始迴圈通常是由應用程式藉由呼叫 Run 來起始。

PushFrame 輸入由 參數 frame 表示的迴圈。 在迴圈的每個反復專案上, Dispatcher 會檢查 Continue 類別上的 DispatcherFrame 屬性,以判斷迴圈是否應該繼續,還是應該停止。

DispatcherFrameContinue允許明確設定 屬性,並遵守 HasShutdownStarted 上的 Dispatcher 屬性。 這表示當 開始關閉時 Dispatcher ,使用預設 DispatcherFrame 實作的畫面將會結束,這可讓所有巢狀框架結束。

適用於

另請參閱