Not logged in. · Lost password · Register
Forum: agsXMPP RSS
Avatar
robertpitt #1
Member since Jul 2010 · 7 posts
Group memberships: Members
Show profile · Link to this post
Subject: Problems with opening message window from background thread.
Heya guys, now i know this is not specifically about agsXMPP but i really need help with it.

im having trouble opening a new message window from the OnMessage callback.

heres the code blocks that im having issues with
        private delegate void OpenMessageWindowDelegate(Object Sender, agsXMPP.protocol.client.Message Message);
        private void OpenMessageWindow(Object Sender, agsXMPP.protocol.client.Message Message)
        {
                MessageWindow MessageWindow;
                RosterItem Roster = ContactManager[Message.From.Bare];
                if (WindowManager.ContainsKey(Roster.Jid.Bare) == false)
                {
                    MessageWindow = new MessageWindow(Roster);
                    MessageWindow.FormClosing += new FormClosingEventHandler(MessageWindow_FormClosing);

                    //Store it.
                    WindowManager.Add(Roster.Jid.Bare, MessageWindow);
                }

                MessageWindow = WindowManager[Roster.Jid.Bare];

                MessageWindow.Show();
                MessageWindow.Activate();
        }

        public void ClientConnection_OnMessage(Object Sender, agsXMPP.protocol.client.Message Message)
        {
            OpenMessageWindowDelegate OpenMessageWindowDelegate = new OpenMessageWindowDelegate(OpenMessageWindow);
            OpenMessageWindowDelegate(Sender, Message);
        }

The way my application is structured is that my base class is a class that extends ApplicationContext, mso when rosters/presence/messages come in there handled outside the regular mainform.

Whats happening is the form is being created but its freezing, witch in turn tells me that for some reason its being created by the BackgroundThread of agsXMPP.

Can anyone help me resolve this.
Avatar
Alex #2
Member since Feb 2003 · 4328 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
You have to invoke events from agsXMPP when they update the GUI. Because agsXMPP events are from another thread than your main GUI thread. This is also described in the MiniClient example.

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:
Forum: agsXMPP RSS