Entrust these two days how much understand point, but easy brain dizzy, summed up under
A delegate is a declaration of an object that allows him to help other programs execute. The Richbox is displayed as a cross-thread.
1 //declaring a named delegate with no return value2 Delegate voidMsghandler (stringtxt);3 //Msghandler Msgdele, Msgdels, Msglambda;4 5 Private voidForm1_Load (Objectsender, EventArgs e)6 {7 //putting a method in a thread8Thread TRD =NewThread (NewThreadStart (Start));9 TRD. Start ();Ten } One A voidStart () - { - //named method instantiation theMsghandler Msgdele =NewMsghandler (msgshow); - - //using named Methods - //Msgdele ("naming method"); //calling within a thread +Rbox. Invoke (Msgdele,"Naming Methods");//for out-of-thread - + //anonymous method delegate type delegate variable = delegate ("parameter list") {code block}; AMsghandler Msgdels =Delegate(stringtxt) at { - msgshow (TXT); - }; - - - //calling within a thread in //msgdels ("anonymous Method"); - to //for out-of-thread +Rbox. Invoke (Msgdele,"Anonymous Methods"); - the * //Lambda declaration Method $Msghandler Msglambda = p = ={msgshow (P);};Panax Notoginseng //Msglambda ("Lambda"); - the //for out-of-thread +Rbox. Invoke (MSGLAMBDA,"Lambda"); A } the + - //Execution Method $ Private voidMsgshow (stringtxt) $ { - //the same as normal use -Rbox. AppendText (txt +"\ r \ n"); the}
C # Commissioned Tutorials Dry