Today will be multi-threaded knowledge has reviewed the next, summed up a few points:
Create a new thread (no parameters, no return value)
- Thread th = new Thread (new ThreadStart (Printname));
- public void Printname () //function
- {
- //function Body
- }
It is important to note that the functions in ThreadStart are not return values and parameters.
Then there are parameters, which are as follows:
- Thread th = new Thread (new Parameterizedthreadstart (Printname));
- Public void Printname (string name) //function
- {
- //function Body
- }
If you encounter and need a return value, and you need parameters, you can consider using async:
But we need to declare a commission.
- Public Delegate string Methodcaller (string name); Define an agent
- Methodcaller mc = New Methodcaller (GetName);
- String name = "My name"; Input parameters
- IAsyncResult result = MC. BeginInvoke (name,null, null);
- String myname = mc. EndInvoke (result); //To receive return values
- Public string GetName (string name) //function
- {
- return name;
- }
Note here that the generation of new threads in this way is running in the background (background), with the priority being normal
C # multithreaded programming, parameters, accepting return values