private static bool __stop = false; private static void Main(string[] args) { Thread[] myThreads = new Thread[5]; for (int i = 0; i < myThreads.Length; i++) { Thread myThread = new Thread(new ThreadStart(DoWork)); myThread.Name = i.ToString(); myThread.Start(); } } private static void DoWork() { while (!__stop) { Console.WriteLine("current thread : {0}", Thread.CurrentThread.Name); } }
private static bool __stop = false; private static Random rand = new Random(); private static void Main(string[] args) { Thread[] myThreads = new Thread[5]; for (int i = 0; i < myThreads.Length; i++) { Thread myThread = new Thread(new ThreadStart(DoWork)); myThread.Name = i.ToString(); myThread.Start(); } } private static void DoWork() { while (!__stop) { Console.WriteLine("current thread : {0}", Thread.CurrentThread.Name); Thread.Sleep(rand.Next(5000)); } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question