Answer the question
In order to leave comments, you need to log in
Why doesn't it enter the Count method on the first iteration of the for loop when creating a new thread?
Hello! I study the program in the debugger:
using System;
using System.Threading;
// Синхронизация потоков
class Program
{
static int x = 0;
static void Main(string[] args)
{
for (int i = 0; i < 5; i++)
{
// создаем новый поток (здесь предположение делегата)
Thread myThread = new Thread(Count);
// имя нового потока
myThread.Name = "Поток " + i.ToString();
// запускаем новый поток
myThread.Start();
}
Console.ReadLine();
}
public static void Count()
{
x = 1;
for (int i = 1; i < 9; i++)
{
Console.WriteLine("{0}: {1}", Thread.CurrentThread.Name, x);
x++;
Thread.Sleep(100);
}
}
}
Thread myThread = new Thread(Count);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question