This project has moved. For the latest updates, please go here.

[en] Events order (solved)

Topics: Technical Support
Oct 9, 2014 at 7:55 PM
Edited Oct 9, 2014 at 8:02 PM
Using revision 42563, TcpDuplexServerProtocolSetup and TcpDuplexClientProtocolSetup.

I have 3 different events: PassStarted, Information, ApStateChanged. PassStarted event have some byte array in args (~40kb).

On server I fire events in order one after another without pauses:
  1. PassStarted
  2. Information
  3. ApStateChanged
On client I received events in different order:
  1. Information
  2. ApStateChanged
  3. PassStarted (most "heavy" event)
So I have not ordered event handlers invocations. Is this behavior really correct, or Zyan or I have a bug?
If this is correct behavior - how can I make invocations ordered?
Oct 13, 2014 at 2:25 PM

event arrival order is not deterministic, this is by design.
Events are fired asynchronously and there is no way to enforce the same order on the remote side.
Looks like PassStarted event arrives last due to network latency because of its extra payload of 40 kb.

To order event data you can add auto-initialized DateTime property to your EventArgs class, i.e.:
public class InfoEventArgs: EventArgs
    public InfoEventArgs(string info)
         EventTime = DateTime.Now;
         Info = info;

    public DateTime EventTime { get; private set; }
    public string Info { get; private set; }
In my application I use this approach for tracing server-side SQL statements.
The grid that displays SQL statements executed on the server is sorted by Time column, so the statements are always displayed in the right order.

Hope that helps!
Marked as answer by zii_dmg on 10/13/2014 at 7:32 AM