CLR via C # Deep solution note five-Events

Source: Internet
Author: User
Event handling is actually a delegate with a special signature, like this: public delegate void EventHandler (object sender, EventArgs e); Type defines an event member, you can notify other objects that something specific has happened. If you define an event member, it means that the type has to provide the ability: #1, the method can be enlisted or it can unregister its attention to the event, which occurs when the registered method receives a notification. The type is able to provide event notification functionality because the type maintains a list of registered methods. After an event occurs, the type notifies all registered methods in the list. The CLR event model is built on the basis of a delegate. A delegate is a type-safe way to call (Invoke) a callback method. The object receives a notification of their subscription with a callback method. --------- invoke and call in the context of English, the difference between invoke and call is that when executing a method that all information is known, call is more appropriate. This information includes the type to be referenced, the signature of the method, and the method name. However, when you need to "call out" something to help you invoke an information-unaware method, invoke is more appropriate. The problem with---------this onboiled method is that the thread may find that boiled is not null, and then, just before the call, another thread removes a delegate from the delegate chain, making boiled null. A NullReferenceException exception is also thrown. To fix this race problem, you can write the Onboiled method as follows

CLR via C # Deep solution note five-Events

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.