Forum > Windows

TDaemon hangs on OnExecute, bug? (Windows 64bit)

(1/2) > >>

MaartenJB:
Hi,

I have a problem with TDaemon, when OnExecute is assigned, you can start de service, but when you try to stop it, windows says it can't stop it.

Reproduce:

1) Open example: ...\lazarus\fpc\3.2.0\source\packages\fcl-extra\examples\double\double.pp
2) Let Lazarus create a new "Daemon (service) application" for it
3) Compile
4) Install the service: double.exe --install
5) Start the "TDaemon1" Service
6) Stop the "TDaemon1" Service
    Now Windows say it can't stop the service, and you have to kill it via the taskmanager.
7) Uninstall the service: double.exe --uninstall

This doesn't happen when OnExecute is not assigned.

Best regards,

Maarten

Lazarus 2.0.12 r64642 FPC 3.2.2 x86_64-win64-win32/win64

GetMem:
@MaartenJB
Spawn a worker thread when the service is starting. For more details please check the attachment from the following post:
https://forum.lazarus.freepascal.org/index.php/topic,57390.msg426821.html#msg426821


Edit: I attached a simplified version of the project. You can do some task(s) on the execute event of the worker thread.

MaartenJB:
@GetMem, Thanks for your reply.

But it should not be necessary to create these threads yourself as it should be handled by: TCustomDaemonApplication as stated in the documentation:

(See Description)
https://www.freepascal.org/docs-html/fcl/daemonapp/tdaemonthread.html

I know how to make a service work with a thread, and that way it causes no problems, but why do this yourself if there is a framework for it?

I'm not saying there is a bug, but if there is a bug in the framework, that should ideally be fixed right? For me the example shipped with Lazarus doesn't work properly.


GetMem:

--- Quote ---I know how to make a service work with a thread, and that way it causes no problems, but why do this yourself if there is a framework for it?
--- End quote ---
Because you have more fine control over it, but OK I got your point.


--- Quote ---I'm not saying there is a bug, but if there is a bug in the framework, that should ideally be fixed right? For me the example shipped with Lazarus doesn't work properly.
--- End quote ---
If you overwrite the Execute method on your TCustomDaemon class, set the function result to false and the thread will just stop fine.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function TDaemon.Execute: Boolean;begin  //do something  Result := False; //add this lineend; 

MaartenJB:
@GetMem, thanks.

I managed to find a solution to my problem with the demo:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---// ...\lazarus\fpc\3.2.0\source\packages\fcl-extra\examples\double\daemonunit1.pas procedure TDaemon1.DataModuleExecute(Sender: TCustomDaemon);Var  I : Integer;begin  I := 0;  Application.EventLog.Log('TDaemon1 execution start');  While Self.Status = csRunning Do Begin    Sleep(10);    Sender.CheckControlMessages(False);  // <-- This will make the status update and exit appropriate   end;  Application.EventLog.Log('TDaemon1 execution stop');end;      
I'm not sure if this is the correct way, maybe someone with a bit more knowledge than me can verify this "fix".

Navigation

[0] Message Index

[#] Next page

Go to full version