Using UniAlerter in a separated thread.

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mindtrap
Posts: 1
Joined: Thu 22 Jul 2021 15:54

Using UniAlerter in a separated thread.

Post by mindtrap » Mon 26 Jul 2021 15:03

Hi,

I tried to use a TUniAlerter within a console application or to be more specific I do have the need to get notifications within a windows service which might run as a console instead of beeing an installed service.
So that's the request I got from my stakeholder.

The service is a multithreaded process. So when I tried to implement a new thread which holds the Alerter and it's own database connection I figured out, that the Alerter.Start method hangs.

To isolate the problem I've setup some test projects.

Case 1
Of course I started my first project using a normale VCL Forms Application.
Having a TUniConnection, OracleUniProvider and a TUniAlerter placed on the form and registering the desired alerts everything went fine.

Case 2
Then I created a simple console application which creates a TUniConnection (connecting to oracle), having a OracleUniProvider used, and creating a TUniAlerter.
In this case I could set the Events property as desired and start the Alerter but nothing happens when an Oracle Alert signals.

Case 3
After realizing (and some debugging within the cpu window) that I have to have a message handling within the process I created a simple message handler like PeekMessage() -> GetMessage() -> TranslateMassage() -> DispatchMessage() within a endless loop.
This case worked.

But in my case I cannot use this solution due to the anatomy of the project I cannot simply block further execution by blocking with a loop.

Case 4
Console application + a TThread which creates the connection and TUniAlerter within the execute method.
Result -> TUniAlerter.Start method blocks when executing.

Case 5
I added a TDataModule and placed all components and using no thread.
After TUniAlerter.Start, which doesn't block in this case, executed alerts aren't receive by the TUniAlerter.


So...
I also debugged the call of TUniAlerter.Start() within the cpu window (assembler code) and noticed that the component distinguishes between running within the main process or a separated thread by looking up the process id.
So I think the component was designed to run in a thread and I'm clearly missing something.

Kind regards.

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Using UniAlerter in a separated thread.

Post by MaximG » Mon 02 Aug 2021 10:43

You are absolutely right. The UniAlerter does not work in console application, since they do not have a native window message handler. If you implement message handling on your own, as you have done, the UniAlerter can be used in console application

Post Reply