아래 스레드 풀 프로그램을 수행했지만 WaitCallBackMethod (여기 ThreadPoolCallback)가 2 번 호출되는 것이 이상적입니다 (이상적으로 1ce라고 함). 내가 만들고있는 쓰레기통은 무엇입니까?스레드 풀 구현 (C# 3.0)의 문제점
public class Calculation
{
#region Private variable declaration
ManualResetEvent[] factorManualResetEvent = null;
#endregion
public void Compute()
{
factorManualResetEvent = new ManualResetEvent[2];
for (int i = 0; i < 2; i++){
factorManualResetEvent[i] = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(ThreadPoolCallback, i);}
//Wait for all the threads to complete
WaitHandle.WaitAll(factorManualResetEvent);
//Proceed with the next task(s)
NEXT_TASK_TO_BE_EXECUTED();
}
#region Private Methods
// Wrapper method for use with thread pool.
public void ThreadPoolCallback(Object threadContext)
{
int threadIndex = (int)threadContext;
Method1();
Method2();
factorManualResetEvent[threadIndex].Set();
}
private void Method1()
{ //Code of method 1}
private void Method2()
{ //Code of method 2 }
#endregion
}
내가
//Initializang all the manual reset events first
Enumerable.Range(0, exposureManualResetEvent.Length).ToList().ForEach(i =>
{
exposureManualResetEvent[i] = new ManualResetEvent(false);
});
Enumerable.Range(0, 1).ToList().ForEach(i =>
{
ThreadPool.QueueUserWorkItem(ExposureThreadPoolCallback, i);
});
중지됩니다 프로그램을 할 경우! 나는 C# 3.0 감사
그럼 난 작동 얻을 inorder를 무엇을해야하는지 .. 나는 당신이 생각하고 싶지 모르겠어요 – Newbie
도와주세요 - 만에 하나의 일을 처리하는 경우 시간이 있고 처리되는 동안 기다려야합니다. 왜 그냥 synch (스레드 없음)로하지 않습니까? – RobS