当前位置:编程学习 > C#/ASP.NET >>

我 写着 优先级怎么没有用

  class Program
    {
        public static int count = 100;
        public static object objent1 = new object();
        static void Main(string[] args)
        {
            //Worker work = new Worker("aaa");
            //Worker work1 = new Worker("bbb");
            //work.thread.Priority = ThreadPriority.Highest;
            //work1.thread.Priority = ThreadPriority.Lowest;
            //work.thread.Start();
            //work1.thread.Start();
            
            Thread thread1 = new Thread(new ThreadStart(aaa));
            thread1.Start();
            Thread thread2 = new Thread(new ThreadStart(bbb));
            thread2.Start();
            thread1.Priority = ThreadPriority.Highest;
            System.Console.ReadLine();
        }
        static void aaa()
        {
            for (int i = 0; i < 50; i++)
            {
                jian1();
                System.Console.WriteLine(count.ToString()+"aaa");
            }
        }
        static int jian1()
        {
            //lock (Program.objent1)
            //{
                if (count > 0)
                {
                    count = count - 1;
                }
                else
                {
                    return 0;
                }
                return count;
            //}
        }
        static void bbb()
        {
            for (int i = 0; i < 50; i++)
            {
                jian1();
                System.Console.WriteLine(count.ToString()+"bbb");
            }

        }
        }
       
    }
--------------------编程问答-------------------- 线程的执行顺序是不定的,与当时的环境和cpu调度有关
顺序Join --------------------编程问答-------------------- ~~~~~~~~~~~~~~``
补充:.NET技术 ,  .NET技术前瞻
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,