I have a rather simple multi-threaded VCL gui application written with Delphi 2007. I do some processing in multiple child threads (up to 16 concurrent) that need to update a grid control on my main form (simply posting strings to a grid). None of the child threads ever talk to each-other.
My initial design involved calling TThread’s “Synchronize” to update the grid control form within the currently running thread. However, I understand that calling Synchronize essentially executes as if it is the main thread when called. With up to 16 threads running at once (and most of the child thread’s processing takes from < 1 second to ~10 seconds) would Window Messages be a better design?
I’ve gotten it working at this point where the child thread posts a windows message (consisting of a record of several strings) and the main thread has a listener and simply updates the grid when a message is received.
Any opinions on the best method for IPC in this situation? Window messages or ‘Synchronize’?
If I use window messages, do you suggest wrapping the code where I post to the grid in a TCriticalSection (enter and leave) block? Or will I not need to worry about thread safety since I’m writing to the grid in the main thread (although within the window message handler’s function)?