Wednesday, 15 April 2015

multithreading - Delphi - application hangs while ShowMessage or MessageDlg -



multithreading - Delphi - application hangs while ShowMessage or MessageDlg -

why application hangs when executing thread , thread have showmessage or messagedlg when using messagebox working normally.

all happened if application appearance not defualt 1 >> "windows"

if selected appearance "windows" never hangs showmessage , messagedlg

showmessage() , messagedlg() not thread-safe. display vcl forms, must used in context of main ui thread.

windows.messagebox() thread-safe, if specify nil owner window when calling worker thread. creates , displays own dialog window, , runs own modal message loop, within context of calling thread, there usually no threading issues. there gotchas (see article: messageboxes , worker threads).

tapplication.messagebox() calls windows.messagebox() internally, not thread-safe because things invoking rtl , mainform not thread-safe, , should used in context of main ui thread well.

in short, don't utilize vcl popup messages in worker threads - period. utilize windows.messagebox(), or on safe side, delegate popup messages main ui thread.

multithreading delphi appearance

No comments:

Post a Comment