我想執行線程中的代碼,並等待for循環完成之前for循環後執行代碼。代碼正在運行之前for循環已完成,線程池c#
for (int i = 254; i > 1; i--)
{
//some code here...
WaitCallback func = delegate (object state)
{
//do something here.... - i want this to finish with the loop first
};
ThreadPool.QueueUserWorkItem(func);
}
// this code is executed once the for loop has finished
// however i want it to be done
// after the thread has finished executing its code and the for loop.
那麼你想跨越254線程? – Tigran
是的,我想這樣做...... – Milan
@Tigran它使用線程池,所以它實際上不會使用254個線程。它只是調度由線程池以線程池認爲最優化的任何方式執行的254個操作,其不涉及254個實際線程。 – Servy