Page 1 of 1

TThread Synchronize creates deadlock

Posted: Mon May 17, 2021 1:38 pm
by sebfischer83
Hi,

I pass a javascript message from my sub-process to my main application with SendProcessMessage(PID_BROWSER,....)
Now when I call anything like MessageDlg or try to show a form with TThread.Synchronize or TThread.Queue it hangs, I suspect this is a deadlock.
What can I do?
And to close the browser form, should this also be in Synchronize? (when I'm in the OnProcessMessageReceived method)

Re: TThread Synchronize creates deadlock

Posted: Mon May 17, 2021 2:19 pm
by salvadordf
Hi,

According to the documentation, TThread.Synchronize suspends the execution of the current thread while the method is executed in the main thread.
http://docwiki.embarcadero.com/Libraries/Sydney/en/System.Classes.TThread.Synchronize

CEF and Chromium don't expect this and some events may freeze the app if you call TThread.Synchronize inside them.

I would use TThread.Queue or send a custom Windows message to the main form to execute your method in the main application thread without locking the current CEF thread.

Re: TThread Synchronize creates deadlock

Posted: Mon May 17, 2021 6:22 pm
by sebfischer83
Thanks, the Window messages do the trick.