One, MSDN description
Delegate class: Represents a delegate, which is a data structure that references a static method or a reference class instance and an instance method of that class. (Does it feel like a function pointer in C language:) )
Namespaces: System
Assembly: mscorlib.dll
Speaking of Delegate, we must talk about Multicastdelagate.
Multicastdelagate class: Represents a multicast delegate, that is, a delegate whose invocation list can have more than one element.
Namespaces: System
Assembly: mscorlib.dll
Inheritance Relationship:
Note:
1. The Delegate class is the base class for the delegate type
2. MulticastDelegate inherits from delegate (this is nonsense, the above inheritance is so obvious)
3. MulticastDelegate has a list of delegates with a link, which is called the invocation list (virtual function table)
4. If an exception occurs when a delegate in the MulticastDelegate's delegate list executes, the delegate after the delegate does not execute
5. The relationship between delegate and delegate and Multicastdelagate in C #:
Marking a method with the delegate keyword in C # The compiler will automatically generate a class that inherits from System.MulticastDelegate, with the method name Class name, and adds the BeginInvoke and EndInvoke methods
usingSystem; Public Delegate voidCustomdelaget (); //using the delegate keyword compiler will automatically generate a class that inherits from System.MulticastDelegate/*. class public auto ANSI sealed customdelaget extends [mscorlib]system.multicastdelegate{}//End of Class Custom Delaget*/classapp{Static voidMain () {customdelaget D=NewCustomdelaget (Invoke); D.invoke (); } Static voidInvoke () {}}
View Code
Ii. using Action and Func instead of custom delegates
The Action represents a delegate that has no return value
Func represents a delegate with a return value
In other words, the action and Func assemblies are a bit weird, and func is like the action Assembly, taking action as an example
Action (T)--The Assembly for Action (T1,T2,T3,T4,T5,T6,T8) is mscorlib.dll
Action (T1,T2,T3,T4,T5,T6,T8,T9)-to-action (T1,T2,T3,..., T16) assembly is System.Core.dll
This gives people the first design of the class library of the people think up to 8 parameters is enough, and later found that 8 parameters are not enough, and added 8 in the System.Core.dll under the feeling
Third, asynchronous
1. Delegate-based asynchronous (traditional async)
2. Event-based Asynchronous
Not finished
Probe into the source--system.delegate of class library