using System;
using System.Collections.Generic;
using System.Text;
using System;
using System.Threading;

namespace Test
{
class Program
{
  class ThreadProc
  {
    int _i = 0;

    public ThreadProc(int i)
    {
      this._i = i;
    }

    public void thread_proc()
    {
      while (true)
      {
        Console.WriteLine("This is thread {0}. Current Time is {1}.",
        _i, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"));

        Thread.Sleep(10000);
      }
    }
  }

    static void Main(string[] args)
    {
      int MAX_THREADS = 70;
      ThreadProc[] tproc = new ThreadProc[MAX_THREADS];
      Thread[] oThread = new Thread[MAX_THREADS];

      for (int i = 0; i < MAX_THREADS; i++)
      {
        tproc[i] = new ThreadProc(i);
        oThread[i] = new Thread(new ThreadStart(tproc[i].thread_proc));
        oThread[i].Start();
      }

      Thread.Sleep(300000);

      for (int i = 0; i < MAX_THREADS; i++)
      {
        oThread[i].Abort();
      }
    }
  }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2021-09-21
  • 2021-07-21
  • 2021-05-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案