Answer the question
In order to leave comments, you need to log in
How to get rid of form freeze when doing work in a thread via Synchronize?
Good day. The situation is this. I create a TThread, in it I run a function through Synchronize, in which a jpeg image is loaded, converted to bmp, operations are performed with the canvas, compression, cropping, etc., then it is converted back to jpeg and saved. So in 1 thread, this scheme works with a bang, but the more threads, the more the main form hangs for the duration of the scripts (and they work in a cycle). I do not provide the code because the question is mostly theoretical. How to get rid of this hang?
Answer the question
In order to leave comments, you need to log in
Oddly enough, do not use Synchronize on long operations! The subject performs an operation in the main thread and, therefore, the main thread has not responded all this time.
Use some data structure in which the main thread does not climb and there is no need for synchronization. And you only need to synchronize the state switching: the thread is running or you can climb.
You can use PostMessage, however, no one knows when the form will pick up the message and you need to carefully monitor who owns what.
Synchronize is needed when you perform operations on visual elements of the VCL. So:
do without Synchronize.
do inside Synchronize.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question