[英]Code not executing after Threadpool C#
我正在嘗試運行線程池,並希望獲得所有線程的運行時。 這是我的代碼。 我想念什么嗎?
static void Main(string[] args)
{
Console.Write("Enter fund symbol: ");
String stockSymbol = Console.ReadLine();
int numberOfFunds = 1;
String[] fundArray = new String[numberOfFunds];
ManualResetEvent[] resetEvents = new ManualResetEvent[numberOfFunds];
var startTime = DateTime.Now;
for (int s = 0; s < numberOfFunds; s++)
{
fundArray[s] = stockSymbol;
resetEvents[s] = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(new WaitCallback(getStats), (object)fundArray[s]);
}//END THREADLOOP
WaitHandle.WaitAll(resetEvents);
runTime((object)startTime);
Console.ReadKey();
}//END MAIN
好像您忘了設置resetEvents
...
順便說一句:我建議您繼續使用Tasks進行多線程工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.