I think a better way is to make sure events are processed fast enough. Once you receive an event, store its data in some buffer. At that point you can decide to discard some lagging data. Then quickly return from the handler so that other events can be processed. Then use a timer that will be fetching frames at a specified frequency and process them there. Even if you get a lag, all "overflowing" events can discard their data (or some other data waiting to be processed) and everything should work. Just be sure to synchronize the buffer if you wish to use multiple threads for that.
Bookmarks