Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Can not dispatch the function for updating the UI
Avatar
navraj #1
Member since Dec 2010 · 9 posts
Group memberships: Members
Show profile · Link to this post
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?
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
When you set a reference to your Ui in the Dispatcher property then MatriX handles all the dispathing for you automatically.
I use rhe following code in my WPF apps:

  1. xmppClient.Dispatcher = this.Dispatcher;

Quote by navraj:
i have tried using dispatcher but WPF does not have an invoke required function

it's Dispatcher.CheckAccess() in WPF. But you don't need it because MatriX does the job for you.

Alex
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters: