Understanding of delegation, event, invoke, and begininvoke

Source: Internet
Author: User

A delegate is a class that is object-oriented. It defines the function signature so that the method can be passed as a parameter of another method parameter. It is type-safe, because the delegate checks whether the stored function reference matches the declared delegate. Any delegate is inherited from: system. mutlicastdelegate.
The delegate includes three methods: begininvoke, endinvoke, and invoke.

Events are a special type of delegation. Events are based on the Windows message processing mechanism, but they are encapsulated better.
In order to wait for something to happen, it is necessary to constantly detect certain judgment variables. After the introduction of event programming, this process is greatly simplified:
The event can be easily determined.ProgramExecution sequence.
When the event driver waits for an event, it does not occupy a lot of resources. The biggest difference between an event driver and a procedural program is that the program does not constantly check the input device, but does not wait until the message arrives. Each input message is queued, wait for the program to process it. If no message is waiting, the program returns the control to the operating system to run other programs.

Event programming is divided into two parts: Event generation (event generator) and event receipt and processing.
A media needs to exist between the sender and receiver. This media is the delegate
When an event is triggered, will it be executed by the corresponding delegate?

In fact, events reflect encapsulation. Event is composed of two methods: add and remove. When you write button1.click + = xxx, you actually use the add method of event. The "-=" method is called. It is the same as the get/Set Method of the attribute. The purpose is to add a new response method from outside the object, delete known response methods, and not trigger an event, or obtain the response method registered by others. The delegate common fields cannot be used.

Thread-related: begininvoke and invoke

Begininvoke: Execute asynchronous delegation on the thread where the basic handle of the control is created. asynchronous execution refers to that the current thread processes begininvoke and suspends the subsequent commands, after this thread completes processing, it executes the ininvoke delegate.

Invoke: Execute the specified delegate on the thread that owns the basic window handle of this control, and immediately jump to the thread that owns it to execute related operations.

 

The true meaning of http://hi.baidu.com/li_hang/blog/item/437b7831fab3941beac4afc6.html invoke & begininvoke

Differences between http://www.cnblogs.com/mashang/archive/2009/08/01/1536730.html invoke & begininvoke

How to call winform in multi-thread of http://www.yesky.com/20030225/1653758.shtml

 

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.