c# - Event Ordering in .NET -


got quick question on event ordering in c#/.net.

let's have while loop reads socket interface (tcp). interface taking care of ordering (it's tcp). let's packet interface written each "packet" in stream, forward next "layer" or next object via event callback.

so here pseudocode:

while (1) {     readsocket();     if (data received = complete packet)         raiseevent(packet); } 

my questions are:

  1. are events generated in order? (i.e. preserve ordering)
  2. i assuming #1 correct, means block while loop until event finishes processing?

you never know how event implemented. it's possible events executed synchronously, in order, , based on meaningful value. it's possible they'll executed synchronously in arbitrary , inconsistent ordering. it's possible won't executed synchronously, , various event handlers executed in new threads (or thread pool threads). it's entirely implementation of event determine of that.

it's rather uncommon see different event handlers executed in parallel (and mean very, very rare), , events come across backed single multicast delegate, meaning order fired in order in added, have no way of knowing if that's case (baring decompiling code). there no indication public api if how implemented.

regardless of of this, conceptual perspective, best not rely on ordering of event handler invocations, , it's best program if various event handlers run concurrently because @ conceptual level, event represents if implementation details more restrictive.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -