Basis of supplementary C # thread pool threads open

The thread into the thread pool, thread pool will automatically thread of execution, the execution order of threads in the thread pool is uncertain

All threads in the pool are background threads can not be changed

 

The thread into the thread pool: the essence is to have a parameter of type object into the thread method, the method can not have a return value

ThreadPool.QueueUserWorkItem (function, object) // This object is passed in the value parameter method

the using the System;
 the using the System.Collections.Generic;
 the using the System.Linq;
 the using the System.Text;
 the using the System.Threading;
 the using System.Threading.Tasks; 

namespace synchronize threads 
{ 
    class Program 
    { 
        static  void the Main ( String [] args) 
        { 
            the ThreadPool .QueueUserWorkItem (Test, 10 ); // the thread into the thread pool 
            the ThreadPool.QueueUserWorkItem (Test, 20 is ); // the thread into the thread pool 
            the Console.ReadKey (); 
        }
        static void   test(object a)//线程1
        {
            Console.WriteLine(a);
           
        }
        static void test1(object a)//线程2
        {
        Console.WriteLine( a);
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/zhangyang4674/p/11414481.html