Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raising events on separate thread

Tags:

I am developing a component which needs to process the live feed and broadcast the data to the listeners in pretty fast manner ( with about 100 nano second level accuracy, even less than that if I can do that) Currently I am raising an event from my code which subscriber can subscribe to. However because in C# event handlers run on the same thread which raises the event, my thread which raises the event will be blocked until all subscribers finish processing the event. I do not have control on subscribers' code, so they can possibly do any time consuming operations in event handler, which may block the thread which is broadcasting.

What can I do so that I can broadcast the data to other subscribers but can still broadcast the stuff quite fast??

like image 565
Hitesh P Avatar asked Sep 18 '13 20:09

Hitesh P


Video Answer


1 Answers

100 ns is a very tough target to hit. I believe it will take a deep understanding of what you're doing and why to hit that kind of performance.

However, asynchronously invoking event subscribers is pretty easy to solve. It's already answered here by, who else, Jon Skeet.

foreach (MyDelegate action in multicast.GetInvocationList()) {     action.BeginInvoke(...); } 

edit: I should also mention that you need to be running on a real-time operating system to give tight performance guarantees to your users.

like image 118
dss539 Avatar answered Oct 17 '22 05:10

dss539