Subject: WPF Cross thread operation
hello all,
i am creating a messenger application in WPF and i am able to login into Openfire server with both agsxmpp and matrix. i created a login screen with user name and password button and a login and cancel button.
when it successfully logs in i want to make the cancel and login button invisible but it does not happen and says the calling thread cannot access this object because a different thread owns it.
i have tried using dispatcher but WPF does not have an invoke required function
here is the code
Private Sub SignIn_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles SignIn.Click
Dim jid As New Jid(txtID.Text)
xmppCon.Password = txtPassword.Password
xmppCon.Username = jid.User
xmppCon.Server = jid.Server
xmppCon.AutoAgents = False
xmppCon.AutoPresence = True
xmppCon.AutoRoster = True
xmppCon.AutoResolveConnectServer = True
Try
xmppCon.Open()
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Sub
Private Sub xmppCon_OnLogin(ByVal sender As Object) Handles xmppCon.OnLogin
Dim ob(0) As Object
ob(0) = sender
Cancel.Dispatcher.BeginInvoke(CType(AddressOf xmppCon_OnLogin, agsXMPP.ObjectHandler), ob)
Cancel.Visibility = Windows.Visibility.Hidden
Debug.Write("lOGGED iN")
End Sub
can somebody give me an idea how it gets done in WPF?
i am creating a messenger application in WPF and i am able to login into Openfire server with both agsxmpp and matrix. i created a login screen with user name and password button and a login and cancel button.
when it successfully logs in i want to make the cancel and login button invisible but it does not happen and says the calling thread cannot access this object because a different thread owns it.
i have tried using dispatcher but WPF does not have an invoke required function
here is the code
Private Sub SignIn_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles SignIn.Click
Dim jid As New Jid(txtID.Text)
xmppCon.Password = txtPassword.Password
xmppCon.Username = jid.User
xmppCon.Server = jid.Server
xmppCon.AutoAgents = False
xmppCon.AutoPresence = True
xmppCon.AutoRoster = True
xmppCon.AutoResolveConnectServer = True
Try
xmppCon.Open()
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End Sub
Private Sub xmppCon_OnLogin(ByVal sender As Object) Handles xmppCon.OnLogin
Dim ob(0) As Object
ob(0) = sender
Cancel.Dispatcher.BeginInvoke(CType(AddressOf xmppCon_OnLogin, agsXMPP.ObjectHandler), ob)
Cancel.Visibility = Windows.Visibility.Hidden
Debug.Write("lOGGED iN")
End Sub
can somebody give me an idea how it gets done in WPF?