The multithreading function in c # is defined in the System. Threading namespace. Therefore, to use multithreading, you must first declare and reference this namespace (using System. Threading ;).
Start thread
As the name implies, "starting a thread" means creating and starting a thread. The following code can be implemented:
Thread thread1 = new Thread (new ThreadStart (Count ));
The Count is the method to be executed by the new thread.
Pause a thread
It means to sleep a running thread for a period of time. For example, thread. Sleep (1000) is used to Sleep the thread for 1 second.
Delete thread
Before deleting a thread, you 'd better determine whether it still exists (through the IsAlive attribute) and then call the Abort method to delete the thread.
Priority
There is no need to explain this. The hreadPRiority attribute in the Thread class, which is used to set the priority, but the operating system cannot accept this priority. A thread has five priorities: Normal, AboveNormal, BelowNormal, Highest, and Lowest. The specific implementation example is as follows:
Thread. Priority = ThreadPriority. Highest;
Suspend thread
The Suspend method of the Thread class is used to Suspend a Thread until Resume is called. If the thread has been suspended, it will not work.
If (thread. ThreadState = ThreadState. Running)
{
Thread. Suspend ();
}
Recovery thread
It is used to restore a suspended thread to continue execution. It does not work if the thread is not suspended.
If (thread. ThreadState = ThreadState. Suspended)
{
Thread. Resume ();
}