Ensure That You Are Running on the UI Thread
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WPF" Height="100" Width="300">
<StackPanel>
<Button Click="ButtonTrue_Click">UI Thread</Button>
<Button Click="ButtonFalse_Click">Non-UI Thread</Button>
</StackPanel>
</Window>
//File:Window.xaml.vb
Imports System.Windows
Namespace WpfApplication1
Public Partial Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub ButtonTrue_Click(sender As Object, e As RoutedEventArgs)
Me.Dispatcher.VerifyAccess()
End Sub
Private Sub ButtonFalse_Click(sender As Object, e As RoutedEventArgs)
Dim del As New VerifyAccessDelegate(AddressOf VerifyAccess)
del.BeginInvoke(Nothing, Nothing)
End Sub
Private Delegate Sub VerifyAccessDelegate()
Private Overloads Sub VerifyAccess()
Me.Dispatcher.VerifyAccess()
End Sub
End Class
End Namespace
Related examples in the same category