开发者

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

开发者 https://www.devze.com 2023-02-21 06:59 出处:网络
Let\'s say I have an event Tick which I call: public class Test { public event Action Tick; public void Test()

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 oper开发者_开发百科ation of this thread that is running Test() be blocked until they have all been called or does it perform this asynchronously?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消