The classes that implement threading application development in C # are included in the System.Threading namespace, and the Thread,threadpool class is more commonly used
The thread class constructor functions as a thread, with two overloaded versions, one with parameters and one without parameters:
Public Thread (ThreadStart start); Public Thread (Parameterizedthreadstart start);
The declarations of ThreadStart or Parameterizedthreadstart types are as follows:
Public Delegate void ThreadStart (); Public Delegate void Parameterizedthreadstart (Object obj);
The steps to create a thread are as follows:
//create a thread without parameters (the function that the thread is associated with has no parameters)ThreadStart Mythreadstart=NewThreadStart (myFunction);//Pass the function that the thread is going to start (delegate? ) into the ThreadStart variable to goThread mythread=NewThread (MyThread);//Creating ThreadsMythread.start ();//Start Thread//create a thread with parametersParameterrizedthreadstart Mythreadstart=NewParameterrizedthreadstart (myFunction);//Pass the function that the thread is going to start (delegate? ) into the ThreadStart variable to goThread MyThread=NewThread (MyThread);//Creating ThreadsMythread.start (obj);//Start Thread
Precautions:
The method that the thread is associated with must be a void return type
Creates a thread that associates a method with a parameter, the type of the argument must be of type object, and can have only one parameter
The associated method is either static or instantiated
C # Multithreading Implementation method