Jud 1 Posted yesterday at 03:14 AM I have a multitasking program that has been running for weeks, but now I'm having problems adding WaitForAll to do some things when all tasks have been finished. First, some minor problems when I add WaitForAll: the main form is no longer responsive - I can't drag it or close it. Mainly though, are problems with updating the screen. Each task has a memo that it updates occasionally. Also, there are labels for the elapsed time and estimated remaining time. These work without WaitForAll but when WaitForAll is added, the program locks up if it tries to write to a memo or change the caption of a label. I know that these aren't thread safe, but they work if WaitForAll isn't in the program. Is there an easy way to get these to work? Share this post Link to post
eivindbakkestuen 47 Posted yesterday at 04:22 AM Use a separate "master" thread to call WaitForAll. Are you already using TThread.Synchronize for the memo updates? Share this post Link to post
Jud 1 Posted yesterday at 04:35 AM So do I need to put all of the stuff where the tasks are called and WaitForAll into a thread, or just WaitForAll? I've tried the memo updates with and without TThread.Synchronize. Share this post Link to post
Remy Lebeau 1396 Posted yesterday at 06:31 AM (edited) TTask.WaitForAll() is a blocking function. If you call it in the main thread, the main message loop will be blocked. That means no UI updates, no TThread.Synchronize() or TThread.Queue() executions, nothing until the wait is finished. There are some simple solutions: You could just call WaitForAll() in a separate thread, not in the main thread. If you must call WaitForAll() in the main thread, then call it in a loop with a short timeout. Each time it times out, call Application.ProcessMessages(). Each time a task is finished, stop waiting on that task. Stop the loop when there are no more tasks to wait on. Edited yesterday at 06:32 AM by Remy Lebeau Share this post Link to post
Jud 1 Posted 15 hours ago Thanks. I don't think that it must be called in the main thread. Share this post Link to post