zoukankan      html  css  js  c++  java
  • 用控制台测试多个线程

    class Program
    {
    static void Main(string[] args)
    {
    ThreadStart num = new ThreadStart(PrintNum);
    Thread ConstrolNum = new Thread(num);

    ThreadStart str = new ThreadStart(PrintStr);
    Thread ConstrolStr = new Thread(str);

    Stopwatch watch = new Stopwatch();
    watch.Start();
    ConstrolNum.Start();
    ConstrolStr.Start();

    while (true)
    {
    if (ConstrolNum.ThreadState == System.Threading.ThreadState.Stopped && ConstrolStr.ThreadState == System.Threading.ThreadState.Stopped)
    {
    watch.Stop();
    Console.WriteLine(watch.Elapsed.TotalMilliseconds);
    break;
    }
    }

    Console.ReadKey();

    }

    private static void PrintNum()
    {
    for (int i = 1; i < 1000; i++)
    {
    Console.WriteLine(i);
    }
    }

    private static void PrintStr()
    {
    for (int i = 1; i < 1000; i++)
    {
    Console.WriteLine("当前数为:{0}", i);
    }
    }
    }

  • 相关阅读:
    bzoj1098 1301
    bzoj3237
    bzoj3170
    bzoj4008
    一些题解
    bzoj4028
    bzoj3196
    redis学习
    quartz学习
    电商618 压测、优化、降级预案
  • 原文地址:https://www.cnblogs.com/qiqiBoKe/p/3141978.html
Copyright © 2011-2022 走看看