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);
            }
        }
    }
  • 相关阅读:
    基于fpga uart学习笔记
    sublime text3 verilog代码编写高级操作篇
    做一个高尚的fpga调参侠
    彩色MT9V034摄像头 Bayer转rgb FPGA实现
    最新 Xilinx vivado IP许可申请
    基于fpga的256m的SDRAM控制器
    如何调用数据链接属性的对话框
    ASP.NET中动态生成验证码的一则方法
    为什么IIS的应用池回收设置默认为1740分钟
    使用SmtpClient发送邮件
  • 原文地址:https://www.cnblogs.com/jiaoluo/p/3550677.html
Copyright © 2011-2022 走看看