Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are events blocking or non-blocking when you call them?

Let's say I have an event Tick which I call:

public class Test
{
    public event Action Tick;

    public void Test()
    {
         Tick();
         Console.WriteLine("Tick Finished");
    }
}

If I have loads of events subscribed to Tick, will the operation of this thread that is running Test() be blocked until they have all been called or does it perform this asynchronously?

like image 802
Callum Rogers Avatar asked Dec 08 '25 22:12

Callum Rogers


2 Answers

All events are blocking. The thread execution will be blocked until all the event handlers registered to this event have been executed.

like image 115
Eugene Avatar answered Dec 11 '25 10:12

Eugene


While Tick() runs, it will block you from progressing further through the code.

To prove it to yourself, write a console app to do just that, that has a bunch of subscribers to the event, and watch to see what happens.

like image 34
BugFinder Avatar answered Dec 11 '25 11:12

BugFinder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!