zoukankan      html  css  js  c++  java
  • 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);
            }
        }
    }
  • 相关阅读:
    无法import的原因(ImportError: No module named *****)
    Mac 安装终端软件
    MyEclipse中拷贝J2EE项目,发布到tomcat中名字一样的解决办法
    微PE工具箱 v2.1 正式版,最好用的PE工具箱
    Windows 10 v2004 (OS Build 19041.329)
    Microsoft Visual C++ 2019 14.27.28914.0[2020.06.03]
    Visual C++ 运行库合集包完整版 v20200603
    VMware-workstation-full-15.5.6-16341506官方版及密钥
    [转载]使用PRIMO组件,让你的硬盘快几倍!
    [转载]goldendict下优质词典简介及安装
  • 原文地址:https://www.cnblogs.com/jiaoluo/p/3550677.html
Copyright © 2011-2022 走看看