开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜