线程

using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.Threading;

namespace  Threads
{
    
class  EntryPoint
    {
        
static   int  interval;

        
static   void  Main( string [] args)
        {

            Console.WriteLine(
" Interval to display results at ?> " );
            interval 
=   int .Parse(Console.ReadLine());
            Thread thisThread 
=  Thread.CurrentThread;
            thisThread.Name 
=   " Main Thread  " ;
            ThreadStart workerStart 
=   new  ThreadStart(StartMethod);
            Thread workerThread 
=   new  Thread(workerStart);

            
// workerThread.Priority = ThreadPriority.AboveNormal;  // 设置进程的优先级

            workerThread.Name 
=   " worker " ;
            workerThread.Start();//suspend()挂起resume()恢复abort()取消
            DisplayNumbers();
            Console.WriteLine(
" Main Thread Finished " );
            Console.ReadLine();
        }

        
static   void  StartMethod()
        {
            DisplayNumbers();
            Console.WriteLine(
" worker Thread Finished " );
        }

        
static   void  DisplayNumbers()
        {
            Thread thisThread 
=  Thread.CurrentThread;
            String name 
=  thisThread.Name;
            Console.WriteLine(
" Starting thread =  "   +  name);
            Console.WriteLine(name 
+   " :Current Culture =  "   +  thisThread.CurrentCulture);
            
for  ( int  i  =   1 ; i  <=   8   *  interval;i ++  )
            {
                
if  (i  %  interval  ==   0 )
                {
                    Console.WriteLine(name 
+   " :count has reached  " +  i);
                }
            }
        }

    }
}

 

不设置优先级: 

100(不设优先级)
 
1000000(不设优先级)
 
设置优先级:
 
100(设优先级)
 
1000000(设优先级)
 
也是1000000(设优先级)
 
10000000(设优先级)
 

你可能感兴趣的:(线程)