コード例 #1
0
        static void RunThreads()
        {
            var sample    = new ThreadSample();
            var threadOne = new Thread(sample.CountNumbers);

            threadOne.Name = "ThreadOne";
            var threadTwo = new Thread(sample.CountNumbers);

            threadTwo.Name     = "ThreadTwo";
            threadOne.Priority = ThreadPriority.Highest;
            threadTwo.Priority = ThreadPriority.Lowest;
            threadOne.Start();
            threadTwo.Start();
            Thread.Sleep(TimeSpan.FromSeconds(2));
            sample.Stop();
        }
コード例 #2
0
        static void RunThreads()
        {
            var sample = new ThreadSample();

            var threadOne = new Thread(sample.CountNumbers);
            threadOne.Name = "ThreadOne";
            var threadTwo = new Thread(sample.CountNumbers);
            threadTwo.Name = "ThreadTwo";

            threadOne.Priority = ThreadPriority.Highest;
            threadTwo.Priority = ThreadPriority.Lowest;
            threadOne.Start();
            threadTwo.Start();

            Thread.Sleep(TimeSpan.FromSeconds(2));
            sample.Stop();
        }
コード例 #3
0
        /// <summary>
        /// 运行线程
        /// </summary>
        static void RunThreads()
        {
            var sample = new ThreadSample();
            var t1     = new Thread(sample.CountNumbers);

            t1.Name = "Thread One";
            var t2 = new Thread(sample.CountNumbers);

            t2.Name = "Thread Two";

            t1.Priority = ThreadPriority.Highest;//设置线程的优先级
            t2.Priority = ThreadPriority.Lowest;
            t1.Start();
            t2.Start();
            Thread.Sleep(TimeSpan.FromSeconds(2));
            sample.Stop();
        }
コード例 #4
0
        public static void ThreadRun()
        {
            ThreadSample sample = new ThreadSample();

            Thread t1 = new Thread(sample.CountNumber);
            Thread t2 = new Thread(sample.CountNumber);

            t1.Priority = ThreadPriority.Highest;
            t2.Priority = ThreadPriority.Lowest;

            t1.Name = "ThreadOne";
            t2.Name = "ThreadTwo";

            t1.Start();
            t2.Start();

            Sleep(TimeSpan.FromSeconds(2));
            sample.Stop();
        }
コード例 #5
0
        public static void Test()
        {
            ThreadSample sample = new ThreadSample();

            Thread t1 = new Thread(sample.CountNumbers);

            t1.Name = "Thread First";
            Thread t2 = new Thread(sample.CountNumbers);

            t2.Name = "Thread Second";

            t1.Priority = ThreadPriority.Highest;
            t2.Priority = ThreadPriority.Lowest;

            t1.Start();
            t2.Start();

            Thread.Sleep(TimeSpan.FromSeconds(2));
            sample.Stop();
        }