问题
I'm doing some work with a radio microcontroller (BLE). The mechanism supported in .NET's GenericAttributeProfile
namespace, is to use an EventHandler
whenever new data comes in (notifications). A problem I'm currently seeing is that, despite my data being sent in order from the radio hardware, the data does not necessarily get dealt with in that order. I'm guessing this is due to the asynchronous manner in which the EventHandler
is invoked (please correct me if I'm wrong). Every time a new piece of data comes in, the event handler is invoked, which then reads the data, and writes to console the data and a static variable which increments every time the event handler is called (not thread safe, but seems to be OK for testing). The data it is printing out if also incrementing, and I can see that the events are being handled out of order.
So my question is, how do I ensure that events are handled in order. From the research I've done, I can only find literature on the order of eventHandler execution. I don't care about that here as I only have 1 eventHandler. I care about the order of event execution
回答1:
UPDATE 09/15/2014
I just wanted to let everyone know that I actually had 2 issue going on. I had originally thought that it had to do with thread timing but that was only part of the problem (for me anyway). After I fixed my thread timing issue I found out, as the original poster had stated, the events are in fact coming in out of order. I have confirmed this issue with Microsoft and they are now working on a fix. As soon as I get a resolution from them I will post it here.
UPDATE 01/08/2015
Microsoft has finally reached out to me and has confirmed the issue. However, they determined that the cost to benefit was too high to add to the 8.1 core so they won't introduce a fix until the next major release of windows.
来源:https://stackoverflow.com/questions/23848634/event-handler-handling-events-out-of-order