안녕하세요. c#의 워커스레드에 대해 질문을 드립니다.
보시면 아시겠지만 도저히 않풀려저 문의를 드립니다.ㅡㅡ;;;
public class SemaPhoreTest1s
    {
        public SemaPhoreTest1s()
        {
            for (int i=1;i<=10;i++)
            {
                int idnums = i;
                Task.Run(()=>TestSemaPhoreSlims("ID:"+ idnums));
              
            }
            Console.WriteLine("MAIN THREAD:"+Thread.CurrentThread.ManagedThreadId);
            Console.ReadLine();
        }
        public async void TestSemaPhoreSlims(string ids)
        {
            int workerThreads, completionPortThreads;
            ThreadPool.GetAvailableThreads(out workerThreads, out completionPortThreads);
            Console.WriteLine("START TestSemaPhoreSlims:ID["+ ids + "] workerThreads>>>" + workerThreads+": times>>>"+DateTime.Now.ToString("HH-mm-ss"));           
            Thread.Sleep(5000);
            //await Task.Delay(5000);  
         
        }
    }
에서 만약 await Task.Delay(5000); 로 하면 Console.WriteLine("START TestSemaPhoreSlims:ID["+ ids + "]... 부분이 딜레이 없이 찍히는데.
Thread.Sleep(5000);로하면 아래와 같은 로그가 나오고
MAIN THREAD:1
START TestSemaPhoreSlims:ID[ID:2] workerThreads>>>2041: times>>>16-06-43
START TestSemaPhoreSlims:ID[ID:1] workerThreads>>>2041: times>>>16-06-43
START TestSemaPhoreSlims:ID[ID:5] workerThreads>>>2041: times>>>16-06-43
START TestSemaPhoreSlims:ID[ID:4] workerThreads>>>2041: times>>>16-06-43
START TestSemaPhoreSlims:ID[ID:3] workerThreads>>>2041: times>>>16-06-43
START TestSemaPhoreSlims:ID[ID:6] workerThreads>>>2041: times>>>16-06-43
START TestSemaPhoreSlims:ID[ID:7] workerThreads>>>2040: times>>>16-06-44
START TestSemaPhoreSlims:ID[ID:8] workerThreads>>>2039: times>>>16-06-45
START TestSemaPhoreSlims:ID[ID:9] workerThreads>>>2038: times>>>16-06-46
START TestSemaPhoreSlims:ID[ID:10] workerThreads>>>2037: times>>>16-06-47
"START TestSemaPhoreSlims:ID[ID:7] workerThreads>>>2040: times>>>16-06-44"이 부분부터 
자꾸 딜레이가 되면서 찍히게 됩니다. 
물론 await를 하면 되긴 하는데. 전 이 이유가 정말 궁금합니다.
Thread.Sleep(5000);는 어차피 각각의 task만 sleep하는거 같고 그래도 
Console.WriteLine("START TestSemaPhoreSlims:ID["+ ids + "]...는 바로바로 딜레이가 없어야 하는데 딜레이가 생겨서입니다.
질문이 두서없지만 부탁을 드립니다....
        
        
                    
                    
                    
                    
                    
    
                    
                    
                    
                    
                    
                
                    [최초 등록일: ]
                    [최종 수정일: 5/28/2023]