1. The difference between a single thread and multiple threads and the advantages of multiple threads
 
When a single-threaded program is executed, the program path (processing items) runs in a continuous order and must be processed first, and then painted later.
Multithreading. For example, a program can execute more than two identical operations at the same time, such as multiple-threaded software that searches for proxies or sends emails in a group, because an operation takes a long time to return network information, but it is idle for the CPU, it takes a long time to search for thousands of IP addresses if it is executed sequentially. If multithreading is used, you can add other searches while waiting, and then wait, which can improve efficiency.
2. The following is an example of how to implement the content between a single thread and multiple threads. You can tell the difference between a single thread and multiple threads in this example. This also depends on the speed at which each computer runs, may be related to the running speed of their computers, so you may see different thread running results
 
 
 
Namespace consoleapplication1
{
Class Program
{
Static void main (string [] ARGs)
{
// Single-thread content
/* Stopwatch stwatch = new stopwatch ();
Stwatch. Start ();
Printnumb ();
Printstr ();
Stwatch. Stop ();
Console. writeline (stwatch. elapsed. totalmilliseconds );
Console. readkey ();*/
 
// Thread this is perhaps the most complicated method, but it provides various flexible control over the thread. First, you must use its constructor to create a thread instance. Its parameters are relatively simple and there is only one threadstart delegate.
// Multi-threaded content
Threadstart printnumb = new threadstart (printnumb );
Thread readnum = new thread (printnumb );
Threadstart printstr = new threadstart (printstr );
Thread readstr = new thread (printstr );
 
 
 
// Next, we will learn about thread control based on the threadstate attribute of the thread. Threadstate is an enumeration type that reflects the state of a thread. When a thread instance is just created, its
 
// Threadstate is unstarted; when this thread is started by calling start (), its threadstate is running;
 
Stopwatch star = new stopwatch ();
Star. Start ();
Readnum. Start ();
Readstr. Start ();
 
While (true)
{
If (readstr. threadstate = system. Threading. threadstate. Stopped & readnum. threadstate = system. Threading. threadstate. Stopped)
{
Star. Stop ();
Console. writeline (Star. elapsed. totalmilliseconds );
Break;
}
}
Console. readkey ();
}
 
Public static void printnumb ()
{
For (INT I = 0; I <1000; I ++)
{
Console. writeline (I );
}
}
Public static void printstr ()
{
For (INT I = 0; I <1000; I ++)
{
Console. writeline ("output" + I. tostring ());
}
}
}
}