Is it poor form for a C# class to subscribe to its own published events?

后端 未结 6 738
难免孤独
难免孤独 2020-12-16 17:06

I\'m probably just being neurotic, but I regularly find myself in situations in which I have class that publishes an event, and I find it convenient to subscribe to this eve

6条回答
  •  既然无缘
    2020-12-16 17:49

    There's a very exotic problem due to internal optimization when doing this. Due to the optimization adding/removing event handlers is not thread safe. It only applies to events that are used by the declaring type like in your example.

    Fortunately this has been changed with 4.0, but if you're on previous version, you could experience this.

提交回复
热议问题