IndySockets / Indy

Indy - Internet Direct
https://www.indyproject.org
459 stars 155 forks source link

Update TIdNotify to support TThread.ForceQueue() #179

Closed rlebeau closed 7 years ago

rlebeau commented 7 years ago

RAD Studio 10.2 Tokyo added a new TThread.ForceQueue() method for RSP-15427, allowing code in the main UI thread to queue a method for delayed execution, whereas TThread.Queue() executes it immediately.

TIdNotify used to have this same feature years ago. When TIdNotify.Notify() was invoked by the main UI thread, and TIdNotify.MainThreadUsesNotify was True, Notify() would spawn a worker thread to queue the notification to the main UI thread. That functionality was lost (but not the property itself) when TIdNotify.Notify() was updated to stop using the worker thread and instead use TThread.Queue() in Delphi/C++Builder 8+.

With TThread.ForceQueue(), TIdNotify.Notify() and TIdNotify.NotifyMethod() can regain the ability to queue methods when invoked by the main UI thread and MainThreadUsesNotify is True, without having to spawn a worker thread to do it (for Delphi/C++Builder 7 and earlier, and FreePascal, the worker thread will still be needed).

rlebeau commented 7 years ago

Implemented in SVN rev 5429.

TIdNotify now supports TThread.ForceQueue() in RAD Studio 10.2 Tokyo and later, and also TThread.Queue() in FreePascal 3.0 and later.

TIdNotify.Notify() now respects the MainThreadUsesNotify property once again. When called in the main thread, if MainThreadUsesNotify is true and TThread.ForceQueue() is not available, Notify() creates an internal worker thread (TIdNotifyThread) to queue the notification. Just like it used to before support for TThread.Queue() was first added.

TIdNotifyThread now uses TThread.Queue() when available, instead of using TThread.Synchronize().

An optional AForceQueue parameter has been added to TIdNotify.NotifyMethod().