Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
rfog #1
Member since Aug 2012 · 6 posts
Group memberships: Members
Show profile · Link to this post
Subject: Is Matrix thread safe and/or can be used from other threads than UI one?
Can be it used from other threads than UI one?

If yes, is Matrix thread safe or we need to use synchronization objects manually?
Avatar
Alex #2
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
yes MatriX uis thread safe. If you encounter any problems let us know.
XmppClient has a Dispatcher property. If you set the Dispatcher of your UI there all events are invoked to your UI thread.

Alex
Avatar
rfog #3
Member since Aug 2012 · 6 posts
Group memberships: Members
Show profile · Link to this post
I'm having some problems here.

I have a class, XmppProcessor, that contains an instance of XmppClient.

I'm doing an completely asynchronous login: I launch a background worker that does the login and waits until a timed ManualResetEvent is fired by OnLogin envent.

  1. class XmppProcessor
  2. {
  3.  private XmppClient xmppClient;
  4.  public XmppProcessor
  5.  {
  6.     xmppClient=new XmpClient();
  7.     //More events subscribing (OnLogin) and so
  8.  }
  9.  public void DoLogin()
  10.  {
  11.     //Creating an BackgroundWorker that calls to xmppClient.Open() => Cross threading exception
  12.  }
  13. }

This is a sample. Serious problem come when I call to other Matrix stuff, that fires cross threading exceptions. This class does not have any UI related access/objects.

I need to login asynchronous because there are times that login does not happens and no error is fired (our XMPP servers problem), and I need some kind of timeout. I simply do not receive OnLogin (or any other On<Event>) and I cannot retry or show error (I can solve this by a timer doing polling, but I think threading is better approach).

My idea is to have one thread to dispatch queued XMPP messages added by my client and other to do the same with IQ.

My short conclusion is that all Matrix stuff must be in the same thread...
This post was edited on 2012-10-19, 14:43 by Alex.
Edit reason: added code formatting
Avatar
Alex #4
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
Set the correct Dispatcher in the Dispatcher property, or set AutoInvoke to false then MatriX does not invoke events to your Dispatcher at all.

Alex
Avatar
z668 #5
Member since Oct 2014 · 5 posts
Group memberships: Members
Show profile · Link to this post
Hello.
Sorry for bad English.
Please add this information in Tutorial.
This is very important.

p.s. spent 30 minutes to search the forum ...
p.p.s. Try to eliminate the events in the following implementations. Events - uncomfortably.

Thanks for good library.
Avatar
Alex #6
Member since Feb 2003 · 4322 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
I'll put this on the TODO list for adding to the tutorial.
The MatriX API is event based, this will also not change in the future. XMPP is an asynchronous realtime protocol, how will you get notifications without evens or callbacks?
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: MatriX RSS