En/na Burkhard Carstens ha escrit:

, but if I don't use synchronize I can move
the window and see the label updating, so I wonder if synchronize is
really (always) needed nowadays.

Yes it is. Of course, there are other ways to solve this, but you should not just ommit synchronize, especially when updating GUI controls.

In your example, you could e.g. use InterlockedIncrement to inc your counter in the thread and update your label in mainthread either in application.OnIdle or with a timer, like:

I wasn't actually interested in updating the counter, it was just a test to see if while I was sleeping ;-) the LCL became automagically thread safe :-D [*] (I still remember the shock when I wrote my first delphi 2.0 heavily multithreaded application only to discover that it didn't work at all because the VCL wasn't thread-safe).

e.g. I also tested adding lines to a memo directly from the thread with no apparent problems.

[*]in fact, a couple of years ago, when I lastly used lazarus for a project, if I used synchronized the program did't work at all (IIRC either it would lock or the synchronized method was triggered more than once), so I just boldly avoided using synchronize. I don't remember the exact details, so it may just have been a fringe case where synchronize wasn't actually needed[**]. It's a simple program but it's been running unattended 24 hours a day since then.

[**]Ok, I looked again at that old code and I cheated: the access to the data was protected with a critical section, but I'm pretty sure I avoided synchronize because it didn't work right at the time.

Bye
--
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007

_________________________________________________________________
    To unsubscribe: mail [EMAIL PROTECTED] with
               "unsubscribe" as the Subject
  archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to