• 多线程05-传参


        class Program
        {
            static void Main()
            {
                var sample = new ThreadSample(10);
                var threadOne = new Thread(sample.CountNumbers);
                threadOne.Name = "ThreadOne";
                threadOne.Start();
                threadOne.Join();
                Console.WriteLine("end threadOne");

                var threadSecond = new Thread(Count);
                threadSecond.Name = "threadSecond";
                threadSecond.Start(10);
                threadSecond.Join();
                Console.WriteLine("end threadSecond");

                var threadThree = new Thread(() => CountNumbers(10));
                threadThree.Name = "threadThree";
                threadThree.Start();
                threadThree.Join();
                Console.WriteLine("end  threadThree");
            }
            static void Count(object iterations)
            {
                CountNumbers((int)iterations);
            }
            static void CountNumbers(int iterations)
            {
                for(int i=1;i<iterations;i++)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(0.5));
                    Console.WriteLine("Thread Name is {0},Prints={1}", Thread.CurrentThread.Name, i);
                }
            }
            static void PrintNumbers(int number)
            {
                Console.WriteLine(number);
            }
            class ThreadSample
            {
                private readonly int _interations;
                public ThreadSample(int interations)
                {
                    _interations = interations;
                }
                public void CountNumbers()
                {
                    for (int i = 1; i < _interations; i++)
                    {
                        Thread.Sleep(TimeSpan.FromSeconds(0.5));
                        Console.WriteLine("Thread Name is {0},Prints={1}", Thread.CurrentThread.Name, i);
                    }
                }
            }
        }
  • 相关阅读:
    [System.currentTimeMillis]/[Calendar.getInstance().getTimeInMillis()]/[new Date().getTime()]
    [Maven]告警[WARNING] Unable to create Maven project from repository.
    通过设置JDK解决存在多个Gradle后台进程的问题
    使用OpenSSL实现X25519秘钥协商功能
    C++代码质量度量工具大阅兵
    Java代码质量度量工具大阅兵
    计算两个时间的时间差(天、小时、分钟、秒数)
    上传文件进度条 (已上传大小、总大小、速度、剩余时间、已用时间)
    table 表格自适应
    谷歌浏览器input框添加了黄色 背景色
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5600189.html
Copyright © 2020-2023  润新知