성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
VC++ / .NET 관련 질문
시작하세요 C# 관련 Q&A
최근 덧글
[정성태] 아래의 글을 보면, MoveWindow 하면 될 듯한데요. ^^...
[Tom Lee] 안녕하세요 올려주신 글 참고하여 WPF 어플리케이션 안에 Uni...
[정성태] A graphical depiction of the steps ...
[정성태] 질문을 주셔서 출판사 측에 문의를 했습니다. 약 한 달 정도 후...
[Thorondor
] @정성태 개인 블로그인데도 거의 커뮤니티 급 인 것 같아요. 요...
[정성태] Roll A Lisp In C - Reading ; https...
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
전체
부모글 보이기/감추기
내용
안녕하세요. 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 + "]...는 바로바로 딜레이가 없어야 하는데 딜레이가 생겨서입니다. 질문이 두서없지만 부탁을 드립니다....
첨부파일
스팸 방지용 인증 번호
2580
(왼쪽의 숫자를 입력해야 합니다.)