By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,239 Members | 1,505 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,239 IT Pros & Developers. It's quick & easy.

Windows Service Written in VB will not stop properly

!NoItAll
100+
P: 296
I have created a small windows service. It starts properly and works as expected. The only problem I am having is when I try to stop it. I get the error: "Service could not be stopped" - but it appears that the service does stop, just not right away. There isn't much code in the OnStop sub:

Expand|Select|Wrap|Line Numbers
  1.         CheckTimer.Stop()  'stops a timer that checks for a running app
  2.         EndApps()   'ends specified running applications
  3.         CheckTimer.Dispose() 'disposes of the timer completely
  4.         Logit("Stopping LCHDWatchdog Service")  'writes an exit message to the log
  5.         Threading.Thread.Sleep(1500)
  6.  
I've tried putting the sleep statement in to see if that helps, but the result is the same.

The application simply starts up and checks to see if a certain application is running (it could be multiple apps). If the apps are not running it will start them.
On close it will close the apps, then it should gracefully exit.
Any suggestions?
Jan 31 '13 #1

✓ answered by !NoItAll

Ok - found the problem. There was a type issue in the EndApps sub. I was concatenating a string in it (for a message to a log) and instead of using the ampersand I used an asterisk.
This generated only a run-time error (the IDE did not catch it) and thus the call threw an error.
So - word to the wise - double check all of the subs/functions in your services to make sure they are solid. Services don't tell you much when there is an error.

Share this Question
Share on Google+
1 Reply


!NoItAll
100+
P: 296
Ok - found the problem. There was a type issue in the EndApps sub. I was concatenating a string in it (for a message to a log) and instead of using the ampersand I used an asterisk.
This generated only a run-time error (the IDE did not catch it) and thus the call threw an error.
So - word to the wise - double check all of the subs/functions in your services to make sure they are solid. Services don't tell you much when there is an error.
Jan 31 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.