• 2.1


    //2.1.4
    //Sleep IsAlive

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Reflection; using System.Runtime.Remoting; public class Threading { static void WorkerFunction() { string ThreadState; for (int i = 1; i < 5000; ++i) { if (i % 50 == 0) { ThreadState = Thread.CurrentThread.ThreadState.ToString(); Console.WriteLine("Worker;"+ThreadState); } } Console.WriteLine("WorkerFunction Complete"); } static void Main() { string ThreadState; Thread t = new Thread(new ThreadStart(WorkerFunction)); t.Start(); while (t.IsAlive) { Console.WriteLine("Still waiting .I'm going back to sleep."); Thread.Sleep(20); } ThreadState = t.ThreadState.ToString(); Console.WriteLine("He's finally done! Thread state is :" + ThreadState); Console.ReadLine(); } }

      

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Reflection;
    using System.Runtime.Remoting;
    
    public class Threading
    {
        public static Thread worker;
        public static Thread worker2;
        static void Main()
        {
            Console.WriteLine("Entering void Main()");
            worker = new Thread(new ThreadStart(FindPriority));
            worker2 = new Thread(new ThreadStart(FindPriority));
    
            worker.Name = "FindPriority()Thread";
            worker2.Name = "FindPriority()Thread2";
            worker2.Priority = System.Threading.ThreadPriority.Highest;
            worker.Start();
            worker2.Start();
            Console.WriteLine("Exitting void Main()");
            Console.ReadLine();
        }
    
        static public void FindPriority()
        {
            //Thread tempThread;
            //System.Threading.Thread.CurrentThread();
            Console.WriteLine("Name ;" + System.Threading.Thread.CurrentThread.Name);
            Console.WriteLine("State :" + System.Threading.Thread.CurrentThread.ThreadState.ToString());
            Console.WriteLine("Priority:" +System.Threading.Thread.CurrentThread.Priority.ToString());
    
        }
    }
    

      

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Reflection;
    using System.Runtime.Remoting;
    
    public class Threading
    {
        static void Main(string[] args)
        {
            Thread.CurrentThread.Name = "主线程";
            Thread thread1 = new Thread(new ThreadStart(Threading.Output));
            thread1.Name = "子线程1";
            thread1.Priority = ThreadPriority.Lowest;
            Thread thread2 = new Thread(new ThreadStart(Threading.Output));
            thread2.Name = "子线程2";
            thread2.Priority = ThreadPriority.Highest;
            thread1.Start();
            thread2.Start();
            Console.ReadLine();
        }
    
        static void Output()
        {
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("线程:{0},i的值:{1}", Thread.CurrentThread.Name, i);
            }
        }
    }
  • 相关阅读:
    SpringCloud入门须知
    24SQL FOREIGN KEY 约束
    23SQL PRIMARY KEY 约束
    python之一列表集合转为字典
    DesktopSwitcher 开发
    Distribute the App on the Website
    Apple Developer账号申请
    后端——框架——视图层框架——spring mvc——注解
    后端——框架——视图层框架——spring mvc——数据(校验,转换,格式化)
    后端——框架——视图层框架——spring mvc——ExceptionResolver
  • 原文地址:https://www.cnblogs.com/jiaoluo/p/3550677.html
Copyright © 2020-2023  润新知