Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Avatar
jwieland #1
Member since Apr 2012 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Event Handlers not firing when threaded?
Is this normal? I am trying to establish multiple connections (5) in this application but when I thread my connection class, I cannot get any EventHandlers to fire.

EventHandlers only fire when not threaded.

Is this by design?


.NET 4 VS 2010 C#
Avatar
jwieland #2
Member since Apr 2012 · 3 posts
Group memberships: Members
Show profile · Link to this post
This is the test class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Matrix;
using System.Diagnostics;

namespace ChatNET
{
    class xmpptest
    {

        Matrix.Xmpp.Client.XmppClient xmppClient = new Matrix.Xmpp.Client.XmppClient();

        public xmpptest()
        {
            xmppClient.OnSendXml += new EventHandler<TextEventArgs>(xmppClient_OnSendXml);
            xmppClient.OnReceiveXml += new EventHandler<TextEventArgs>(xmppClient_OnReceiveXml);
        }

        public void Login()
        {
            xmppClient.SetUsername("xxxxx");
            xmppClient.SetXmppDomain("chat.facebook.com");
            xmppClient.Password = "xxxxx";

            xmppClient.StartTls = false;
            xmppClient.Open();
        }

        private void xmppClient_OnSendXml(object sender, TextEventArgs e)
        {
            Debug.WriteLine("SEND: " + e.Text);
        }

        private void xmppClient_OnReceiveXml(object sender, TextEventArgs e)
        {
            Debug.WriteLine("RECEIVE: " + e.Text);
        }
    }
}

When calling from my main form to test, this works fine (send/receive shows up in debug):
        private void button17_Click(object sender, EventArgs e)
        {
            xmpptest xmpp = new xmpptest();
            xmpp.Login();
        }


This does not (nothing shows up in debug):
        private void button17_Click(object sender, EventArgs e)
        {
            Thread t = new Thread(TryIt);
            t.Start();
        }

        private void TryIt()
        {
            xmpptest xmpp = new xmpptest();
            xmpp.Login();
        }
Avatar
Alex #3
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
this should solve your problem:
http://forum.ag-software.de/thread/1250-can-t-receive-call…

Alex
Avatar
jwieland #4
Member since Apr 2012 · 3 posts
Group memberships: Members
Show profile · Link to this post
Alex! Thank you so much, this was it!
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: