in reply to Win32::Daemon Experience offered/requested

Thank you so much for your work investigating this module.

How would I handle a "while()" loop in the "SERVICE_RUNNING" state? I tried to do modify your code to do this:

# Evaluate STATE if( SERVICE_RUNNING == $State ) { $Context->{count}++; Log( "Running!!! Count=$Context->{count}. Timer:".Win32::Daemon::Cal +lbackTimer() ); my $x = 1; while( $State != SERVICE_STOP_PENDING && $State != SERVICE_STOPPED ) + { Log($x); $x++; sleep 2; } }


However, when I attempt to stop the service, the Windows Service Manager does not stop it. It eventually times out after 2-3 minutes and complains that it couldn't stop it.

Do I have to fork() my while loop as a child process? Or are my while() loop conditions just wrong?

Replies are listed 'Best First'.
Re^2: Win32::Daemon Experience offered/requested
by dolmen (Beadle) on Sep 24, 2009 at 08:18 UTC
    You must update $state inside your loop:
    $state = Win32::Daemon::State();
    Or better, just put only your job timeslice inside the $state == SERVICE_RUNNING condition as there is already a loop outside.
      Neither of those solutions work because it is still waiting for the sleep() to finish. This is apparent when I increase the sleep from 2 seconds to 500 seconds, which better emulates the time-intensive function that my program is doing (enumerating all files on the hard drive and adding their sizes). Any other ideas on how to handle this?