Re: Delphi threading




alanglloyd@xxxxxxx wrote:
DCoder_ wrote:
Very helpful Alan, thanks.

I'm still waiting on knowing why the above code requires a sleep in
order to work though.

Works OK for me _without_ a Sleep().


Further investigation shows that I get an AV (with a reference to a
graphics canvas) if I click the button again while a messagebox is
displayed. So I think it is to do with the ShowMessage() being in the
VCL context and hence should have been wrapped in Synchronise as I
exampled.

If I change the code to wrap the ShowMessage in Synchronize, then of
course the button does not generate a click. If I write the messages to
a listbox on the form and wrap the ListBox writing in synchronize then
again it works OK with multiple button pushes..

You could experiment with putting enough Sleep() in the thread Execute
to generate many concurrent threads by button clicks before a message
occurs (say 5000). Then see what happens.

Alan Lloyd

.


Quantcast