Are C # events connected in series or in parallel?

For example, I have a class that fires an event, and 1000 subscribers to this event. Is one stream used for each delegate of each subscriber one after another? Or does .NET use a thread pool to process some or all of the signatures in parallel?

+4
source share
2 answers

As Tigran said, the challenge of the event is serial. Even more, if one of the subscribers throws an exception at some point, the rest of them will not be launched.

The easiest way to trigger a parallel event is

    public event Action Event;

    public void Trigger()
    {
        if (Event != null)
        {
            var delegates = Event.GetInvocationList();
            Parallel.ForEach(delegates, d => d.DynamicInvoke());
        }
    }

This implementation will suffer from the same problem in the event of an exception.

+2
source

, - . , , .

: .NET, .

+3

Source: https://habr.com/ru/post/1544852/


All Articles