Loop in Dispatch.Invoke Not Updating UI
-
In my application I have a window with a custom look and title bar. The XAML for my window is:
I would like to be able to blink the title bar under some circumstances from a second thread using a loop. For testing purposes I am using the button to start the thread to blink the title bar between green and red with a half-second delay in between the changes. In the button's click event I create a thread and start it:
Private Sub Button_Click(sender As Object, e As RoutedEventArgs)
Try
Dim thread As New Thread(AddressOf ChangeTitleBarColor)
thread.Start()
Catch ex As Exception
Dim m As String = ex.Message
End Try
End SubI've only used the
Dispatcher
a couple of times, so to initially test theChagneTitleBarColor
method and ensure I was using theDispatch
correct I used the following code:Private Sub ChangeTitleBarColor() Try titlebar.Dispatcher.Invoke(Threading.DispatcherPriority.Render, Sub() titlebar.Background =