The delegate can be understood as the function pointer in C or C ++. Calling the delegate actually calls the delegate method.
The procedure for using delegation is as follows:
1. Define Delegation
// Define the delegate use keyword delegate
Private delegate void setprogressbarvaluedelegate (INT value );
2. Declare Delegation
Private setprogressbarvaluedelegate setprogressbarvalue;
3. instantiate the delegate
Setprogressbarvalue = new setprogressbarvaluedelegate (setprogressbarvalue1 );
Setprogressbarvalue1 is the name of the delegate method. The parameter type must be consistent with the delegate type. The prototype is as follows:
// Set progress bar 1
Private void setprogressbarvalue1 (INT value)
{
Pgprogressbar1.value = value;
}
4. Delegated use:
Setprogressbarvaluemethod (setprogressbarvalue );
// Set the progress bar value
Private void setprogressbarvaluemethod (setprogressbarvaluedelegate)
{
For (INT I = 1; I <= 100; I ++)
{
Application. doevents ();
Thread. Sleep (50 );
Setprogressbarvaluedelegate (I );
}
}
/* This Command tells the system to continue processing other events on the user interface to avoid false positives.
* Equivalent to Visual Basic 6.0 doevents ()
* Processing events () in easy language ()*/
Application. doevents ();
/* This command is used to suspend a thread (parameter: millisecond)
* If it is used in the main thread, it will lead to a false death. You can only pause it to make it clearer */
Thread. Sleep (50 );
Zookeeper
C # simple steps for using Delegation