事件处理程序无序处理事件(Event handler handling events out of order)

编程入门 行业动态 更新时间:2024-10-28 06:23:57
事件处理程序无序处理事件(Event handler handling events out of order)

我正在用无线电微控制器(BLE)做一些工作。 .NET的GenericAttributeProfile命名空间支持的机制是在新数据进入(通知)时使用EventHandler 。 我目前看到的一个问题是,尽管我的数据是从无线电硬件按顺序发送的,但数据不一定按此顺序处理。 我猜这是由于调用EventHandler的异步方式(如果我错了请纠正我)。 每次进入新的数据时,都会调用事件处理程序,然后读取数据,并向控制台写入数据和静态变量,该变量在每次调用事件处理程序时递增(不是线程安全的,但似乎是好的测试)。 如果也递增,它打印出的数据,我可以看到事件正在按顺序处理。

所以我的问题是, 我如何确保按顺序处理事件 。 从我所做的研究中,我只能找到有关eventHandler执行顺序的文献。 我不关心这里,因为我只有1个eventHandler。 我关心事件执行的顺序

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

最满意答案

更新09/15/2014

我只是想让每个人都知道我实际上有2个问题正在进行中。 我原本以为它与线程计时有关,但这只是问题的一部分(对我来说无论如何)。 在我解决了线程计时问题后,我发现,正如原始海报所说,事件实际上是乱序。 我已经向Microsoft确认了这个问题,他们正在努力解决这个问题。 一旦我得到他们的决议,我会在这里发布。

更新2015年8月1日

微软终于联系了我并确认了这个问题。 但是,他们确定,为了增加8.1核心,获益的成本太高,因此在下一个主要版本的Windows发布之前,他们不会引入修复。

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.

更多推荐

本文发布于:2023-07-21 09:25:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1208954.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:事件   程序   Event   handler   events

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!