static void MainThread(Object state)
{
for(int i = 0; i < 5; i++)
{
Console.WriteLine("Hello Thread");
}
}
static void Main(string() args)
{
ThreadPool.SetMinThreads(1, 1);
ThreadPool.SetMaxThreads(5, 5);
for (int i = 0; i < 5; i++)
{
Task t = new Task(() => { while (true) { } }, TaskCreationOptions.LongRunning);
t.Start();
}
ThreadPool.QueueUserWorkItem(MainThread);
//Thread t = new Thread(MainThread);
//t.Name = "Test";
//t.IsBackground = true;
//t.Start();
Console.WriteLine("Hello, World!");
}
기본적으로 멀티스레딩은 스레드로 구현됩니다.
ThreadPool의 경우 스레드 수를 조정할 수 있으며 하나의 작업이 완료될 때까지 작업이 계속됩니다.
작업은 TaskCreationOptions.LongRunning을 사용하여 하나의 작업만 실행되지 않도록 합니다.
