There are several variations of the scenario you were talking about. I will try to get through them:
- The best way to solve your problem:
Avoid using events in a parallel scenario if you are considering a multithreaded situation, there is no ideal solution for a .NET event.
Especially if you have a high level of concurrency among consumers / subscribers (a large number of additions / deletions of delegate streams), you can check additional information in this article: http://www.codeproject.com/Articles/37474/Threadsafe-Events
By the time I wrote the article a few days ago, you have everything you need to know about the event in .NET. In addition, some solutions to problems / limitations, how to be simple and how to write good code: http://www.codeproject.com/Articles/864690/Simplifying-Events-in-NET
- Introducing the synchronization mechanism
You just need to use the same synchronization mechanism for each event or for all of them, maybe ManualResetEventSlim or Semaphore or lock among producers (who will raise this event) and consumers (who will add / remove delegates), you can guarantee that You will not lose information.
The biggest problem with this solution is raising the event. If you place a delegate call inside the synchronization mechanism, there may be a dead end or poor performance, because the responsibility will be focused on what delegate subscribers / consumers will do, which is generally poor design.
- Using Reactive Extensions
In this case, with Rx, you can use the same scheduler to subscribe and to raise an event that introduces synchronization, in this part it is important to change the scheduler at runtime to avoid the same problems that I mentioned about using the manual synchronization mechanism. For instance:
static EventHandler _handler; static EventLoopScheduler _eventLoopScheduler = new EventLoopScheduler();
In the above example, I just used one subscriber, but you will be fine with more than one. I know that sometimes itβs not so easy to understand, because multithreading is a difficult thing, but you can add information or ask questions.