Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4.  
  5. namespace MultiThreadedJoins
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int timeout = 1000;
  12.             List<Thread> tlist = new List<Thread>();
  13.             for (int i = 0; i < 10; i++)
  14.             {
  15.                 Thread t = new Thread(MethodName);
  16.                 tlist.Add(t);
  17.                 t.Start(timeout);
  18.             }
  19.  
  20.             foreach (var t in tlist)
  21.             {
  22.                 bool finished = t.Join(timeout);
  23.                 t.Abort();
  24.                 Console.WriteLine(finished.ToString());
  25.             }
  26.  
  27.             Console.Read();
  28.         }
  29.  
  30.         private static void MethodName(object data)
  31.         {
  32.             Thread.Sleep(10000);
  33.             Console.WriteLine("fish");
  34.         }
  35.     }
  36.  
  37.    
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement