Sign in to follow this  
Followers 0
MichaelM

Application does not stop when set as a service

12 posts in this topic

Hi folks

I created an application and I set it up as a service using the guidlines posted in the forums - there is a group of scripts called services.au3

Anyway the service is working fine it starts straightaway but when I go to stop it it does not stop I have to kill the process in order for it to stop.

Is there something I need in the application to allow it to say a stop request has been made please exit.

The script has a while loop in it that makes it loop every 2 minutes indefinitely - (the script is checking the status of the services on the box ironically)

So is due to the while loop perhaps or am I just way off the mark.

I am by no means a super programmer so go easy on me

Michael

Cheers

Share this post


Link to post
Share on other sites



Just off the top of my head, It might not be stop if depending on how the 2 minute event you mentioned is coded. Also, how are you running it as a service? With a 3rd party tool or using the Service code demonstrated

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

It would be easier to help if you posted your code here.

:x

Just saying.

But @ your problem, the reason why this happens is because AutoIt scripts don't close by default until the loop is satisfied. In other words, you'll have to end the loop internally if you don't want this problem to occur externally.

spudw2k, the UDF you posted is probably too complex for someone fairly new to AutoIt. Besides, I don't think that's the solution to his problem. o.o

Edited by Kalin

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

spudw2k, the UDF you posted is probably too complex for someone fairly new to AutoIt. Besides, I don't think that's the solution to his problem. o.o

I'd say the UDF would only make things too complex if you look at the backend code dealing with the SCM. :x It is a beast I admit, but there are very simple examples and it's definitely worth researching if the intention is to make an AutoIt Script that functions as a service.

It would be easier to help if you posted your code here.

Agreed

Edited by spudw2k

Share this post


Link to post
Share on other sites

HI spudw2k

Yes I am using the UDF as described and the service does install and starts and functions correctly but I don't obviously have a provision for stopping.

I have no problem posting code I have attached the file below.

I don't think the loop method is the most efficient however within the scope of my knowledge it is the best I could do so any help on improving this script would be really appreciated.

Cheers

MIchael

ServiceMonitoring.au3

Share this post


Link to post
Share on other sites

Just a couple of things.

When I used the Service UDF, it would call the func Main, but I don't see that in your code. Not sure if that's causing the problem or if you changed the UDF on your machine.

Anyways, here's what I recommend as far as the pause/sleep.

Instead of doing a sleep, have a timer running and if that timer reaches the desired duration, run the main code and reset the timer. The sleep command more-or-less hangs the process from what I understand.

Share this post


Link to post
Share on other sites

Hiya,

Do you have any examples of using a timer function, never thought of that I have used them before in VB.

I will check the Main() function I kind of figured this was just the way the example was coded.

When the stop command is sent from the Service control manager I wonder is there anything you need in your code to react to, I was thinking if I am sleeping for 2 minutes and then just looping I am not looking for something asking me to shutdown - now might not be needed but just a thought.

Share this post


Link to post
Share on other sites

Timer Function example

Func _Sleep($mSecsToSleep)
    Local $StartTimer
    $StartTimer = TimerInit()
    While 1
        If TimerDiff($StartTimer) >= $mSecsToSleep Then Return
        Sleep(10)   ;nominal sleep time to ease process consumption but maintain control of the System 
    WEnd
EndFunc

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Can't delete accidental double post

Edited by Varian

Share this post


Link to post
Share on other sites

what is the benefit of using the timer versus sleep.

also any further thoughts on how to get my app to respond to the stop command.

Share this post


Link to post
Share on other sites

Hi folks,

I noticed also that since I made the app a service it is no longer detecting that a service has stopped which is annoying..

Any thoughts as to why that is.

Share this post


Link to post
Share on other sites

the trail goes cold I think....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0