try cyrax answer first I think it will solve your problem eg
*Very* Old quote from Peter Below:
" It queues a method call for the main
thread to execute, like Synchronize, but it does not wait for it to be
executed."
OK So far so good, I just don't understand where the conclusion that
The queue methods are meant and designed to be on thread termination: it is not meant to be used for intermediate results... never has been.
comes from, but that is outside the scope of this thread.
Which is *exactly* what I wrote. The TThread.Queue method mentioned in the thread header is already Asynchronous.
If the queue is not empty, it is safe to execute the method or use the data in the Owner. Usually the main thread.
true the queue method is asynchronous. as for the Queue it self the only certain thing, if it is not empty, is that it has one or more methods to be executed, if it is safe to execute them or not is an other matter altogether and it is not addressed by the queue, it can not be addressed by it actually. In this case I assume since the queued method is a method of the running thread, it is only safe as long as the running thread does not get freed before the method is executed.
The main problems of the posted code sample are 2
1) On console application there is no basic "application loop" running that will check the queue for you, unless you call the checksynchronize procedure manually, the queued methods will never be executed.
2) The use of blocking functions like readln will not allow proper synchronization between the two threads and it might lead to false interpretations of the observed results.
The solution is to fix those two points and take an other look on the results.
Now there are a lot more to this thing than that, for example I never looked closely if the queued method access shared data with out locking, the next major group of attention but this comes when the OP hits those problems and can't figure it out, the problem is that those kind of problems are not easily observed so it might take him/her some time to notice them.