说你喷,你还有意见,我在8楼一开始揍写了阿?
“你先告诉我event和delegate的区别是啥?event only allows subscribe and unsubscribe, delegate also allows assign and invoke“
为毛不推荐直接对delegate用+=? 你都是调用链了,又暴露在外的接口,我一个对delegate的赋值,你还multicast个屁啊!
咱还不说县城安全的问题,你非要自己玩multicast,好吧,县城同步的代码也请你实现了吧!
所有这些我在8楼都有说啊?你有看吗?亲!
8楼的帖子只是介绍了event为什么是线程安全的
但是你是从哪里看到不推荐delegate使用+=的?[/quote]
你说我木有搞清两者的关系,可见你木有认真看偶在8楼的回帖,我说的对吧?
你发给我的那个tutorial能说明啥?
Delegates are the basis for Events.
上面是你引用给我看的,那个Events是首字母大写,而且还用了复数!可我说的event都是小写哦!为毛?因为那是keyword event。
麻烦你先去搞搞清楚Events和event的区别吧!
先请你告诉我哪句话是在喷?
如果你没用过并且认为不该用,请你先学习下微软提供的关于delegate的教程https://msdn.microsoft.com/en-us/library/ms173172.aspx[/quote]
你先告诉我event和delegate的区别是啥?event only allows subscribe and unsubscribe, delegate also allows assign and invoke
field-like event is backed by a private delegate
When compiling a field-like event, the compiler automatically creates storage to hold the delegate, and creates accessors for the event that add or remove event handlers to the delegate field. In order to be thread-safe, the addition or removal operations are done while holding the lock (§8.12) on the containing object for an instance event, or the type object (§7.6.10.6) for a static event.
然而,如果你自己定义event的add/remove, the thread safe is on you.
有人说反编译会看到.net framework default的event add/remove handler中的lock。我是木有看过,要不你自己试试?