How do I “DoEvents” in WPF?

前端 未结 5 1871

I\'ve read that the C# version is as follows:

Application.Current.Dispatcher.Invoke(
          DispatcherPriority.Background,
          new Action(delegate {         


        
5条回答
  •  别那么骄傲
    2020-12-15 13:47

    You've got two questions here, so i'm going to add two answers. Here, i'm answering "how to do DoEvents in WPF". Bea Stollnitz covers this on her blog, and here's the code in VB:

    publicShared Sub WaitForPriority(priority As DispatcherPriority)
        Dim frame As New DispatcherFrame()
        Dim dispatcherOperation As DispatcherOperation = Dispatcher.CurrentDispatcher.BeginInvoke(priority, New DispatcherOperationCallback(ExitFrameOperation), frame)
        Dispatcher.PushFrame(frame)
        If dispatcherOperation.Status <> DispatcherOperationStatus.Completed Then
            dispatcherOperation.Abort()
        End If
    End Sub
    
    Private Shared Function ExitFrameOperation(obj As Object) As Object
        (DirectCast(obj, DispatcherFrame)).[Continue] = False
        Return Nothing
    End Function
    

提交回复
热议问题