Here is my code
PartsToTranslateCount = PartsToTranslate.size();
_di_ITask* ThreadList;
for (int i = 0; i < PartsToTranslateCount; i += nbMaxThreads->Value) {
ThreadCount = System::Math::Min(int(nbMaxThreads->Value), int(PartsToTranslateCount - i));
ThreadList = new _di_ITask[ThreadCount];
memoTranslatedText->Lines->Add("cicle #-" + IntToStr(i));
for (int j = 0; j < ThreadCount; j++) {
ThreadList[i + j] = TTask::Create([this, i, j]() {
TThread::Synchronize(nullptr, _di_TThreadProcedure([this, i, j] {
Application->ProcessMessages();
this->memoTranslatedText->Lines->Add(IntToStr(i + j));
}));
});
ThreadList[i + j]->Start();
}
TTask::WaitForAll(ThreadList, (sizeof(ThreadList[0]) * ThreadCount) / sizeof(ThreadList[0]) - 1);
//TTask::WaitForAll(ThreadList, ThreadCount - 1);
//TTask::WaitForAll(ThreadList, sizeof(ThreadList)/sizeof(ThreadList[0])-1);
delete[] ThreadList;
}
memoTranslatedText->Lines->Add("Done");
The program hangs unless the line TTask::WaitForAll is not commented
Help solve the problem.
thank you all