Simple understanding of Delegate/event/thread parameter passing

Source: Internet
Author: User

I wrote a lot of code, but almost never wrote code for the Delegate/event/thread parameter passing application.
Therefore, it is easy to understand and forget.
Today I reviewed it again.
Therefore, write down the code in the simplest way to help you understand it.

1. Passing parameters by thread [several simple lines of code]
 

1 static void main (string [] ARGs)
2 {
3 if (threadpool. queueuserworkitem (New waitcallback (program. writepara), "this is the passed parameter "))
4 {
5 console. writeline ("OK :");
6 console. Read ();
7}
8
9}
10 protected static void writepara (Object para)
11 {
12 console. writeline ("Hello:" + para );
13}
14
15

2. Delegate/event

1 public class Program
2 {
3 delegate void callfunction (Object para); // defines the delegate [This is a sample of defining a method. It is simply understood as static with Delegate]
4 Private Static event callfunction callevenhandle; // defines an event. [simple understanding: events must be delegated.]
5 static void main (string [] ARGs)
6 {
7 // call the delegate. the previously defined image method. Here a new instance is provided, which is similar to the new function of Js.
8 callfunction cf = new callfunction (writepara );
9 cf. Invoke ("Goodmorning ");
10
11
12 // call the event. Press the "tab" key after adding "+ =". It is easy to use.
13 callevenhandle + = new callfunction (writepara );
14 callevenhandle ("cyq ");
15
16 // console. Read ();
17}
18
19 protected static void writepara (Object para)
20 {
21 console. writeline ("Hello:" + para );
22}
23}
24

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.