Should C# event handlers be exception safe?

后端 未结 6 1951
梦如初夏
梦如初夏 2021-02-05 07:14

Assuming that one event has multiple handlers, if any of event handlers throw an exception then the remaining handlers are not executed.

Does this mean that event handle

6条回答
  •  忘掉有多难
    2021-02-05 07:53

    In an ideal world, yes. It's a good idea to try to design event handlers so that they:

    • Don't throw exceptions
    • Execute very quickly

    Not doing so will result in unexpected side effects, since other subscribers to the event may never receive messages, or receive them very late.

提交回复
热议问题