Answer the question
In order to leave comments, you need to log in
How to force ThreadPool to start threads correctly?
Hello. There is a task to torture C # but make it work as I need.
In general, there is a method that is called in a multithread. Here it is called 9 times.
In each thread, the timing will be different, that is, the operating time will be different.
static void Main()
{
ThreadPool.SetMaxThreads(3, 3);
for (int i = 0; i < 9; i++)
ThreadPool.QueueUserWorkItem(JobForAThread, new object[] { i });
Console.ReadLine();
}
static void JobForAThread(object state)
{
object[] array = state as object[];
int x = Convert.ToInt32(array[0]);
Console.WriteLine("цикл {0}, выполнение внутри потока из пула {0}", x,
Thread.CurrentThread.ManagedThreadId);
Thread.Sleep(10000);
Console.WriteLine("Закончил работать {0}", x);
}
The maximum number of worker threads or I/O completion threads in Number cannot be set less than the number of processors on the computer. To determine how many processors are present, get the value of the Environment.ProcessorCount property. Additionally, you cannot set the maximum number of worker threads or I/O completion threads to a number less than the corresponding minimum number of worker threads or I/O completion threads. To determine the minimum thread pool size, call the GetMinThreads method.
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