Facebook
From Sole Marmoset, 6 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 268
  1. using System;
  2. using System.Threading;
  3. using System.Diagnostics;
  4. namespace lab1
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             int time = 1000000;
  11.             while(true)
  12.             {
  13.                 Thread th = new Thread(delegate ()
  14.                   { Thread.Sleep(time); });
  15.                 th.Start();
  16.             }
  17.         }
  18.  
  19.  
  20.         static void threads()
  21.         {
  22.             Stopwatch stopw = new Stopwatch();
  23.             stopw.Start();
  24.             int threadcount = 1000;
  25.             for (int i = 0; i < threadcount; i++)
  26.             {
  27.                 Thread th = new Thread(delegate ()
  28.                 { });
  29.                 th.Start();
  30.                 th.Join();
  31.             }
  32.             stopw.Stop();
  33.             Console.WriteLine(stopw.ElapsedMilliseconds + "ms");
  34.             Console.Read();
  35.             stopw.Reset();
  36.         }
  37.     }
  38. }
  39.