zoukankan      html  css  js  c++  java
  • 多线程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);
                    }
                }
            }
        }
  • 相关阅读:
    2013414
    Juqery Html(),append()等方法的Bug
    UpdatePanel 与 jQuery
    (C#)方法参数关键字:ref、out、params详解
    ASP.NET MVC 3 RC2 版本的一些新特性及AllowHtml属性Bug解决办法
    [hystar整理]Entity Framework 教程 转
    SQL 中in exists 和临时表用法
    ASP.NET 用户控件自定义属性、方法、事件
    SQL选择不重复记录
    sql over 用法
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5600189.html
Copyright © 2011-2022 走看看