Loop in Window Service

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I wrote a window service in VB6, where I used a loop to continue check
something. Now, I transfer it into vb.NET. I can setup service with a mis
file, but when I start the service, it takes a while to complete and gives at
the end an error. As long as I remove the loop (a single run) it works
properly. Anyone can give an explanation and solution. How to a window
service in a continue way.

Thanks
 
Li Pang said:
when I start the service, it takes a while to complete and gives at
the end an error.

Your service should do /as little as possible/ in the OnStart routine,
preferably just starting a [one-off] Timer from whose Timer Event the
Real Work gets started.
This allows the OnStart routine to return (to the Service Control
Manager) more quickly, preventing this error.

Sub OnStart()
tmrRunner.Interval = 500
tmrRunner.Enabled = True
End Sub

Sub tmrRunner_Timer
tmrRunner.Enabled = False

Do While True
' Do the Real Job
End Do

End Sub

HTH,
Phill W.
 
Hi Phill. W,
FW 1.1 SP1 can't help to resolve the problem, but using a timer seems very
useful. Thanks for your suggestion.

Phill. W said:
Li Pang said:
when I start the service, it takes a while to complete and gives at
the end an error.

Your service should do /as little as possible/ in the OnStart routine,
preferably just starting a [one-off] Timer from whose Timer Event the
Real Work gets started.
This allows the OnStart routine to return (to the Service Control
Manager) more quickly, preventing this error.

Sub OnStart()
tmrRunner.Interval = 500
tmrRunner.Enabled = True
End Sub

Sub tmrRunner_Timer
tmrRunner.Enabled = False

Do While True
' Do the Real Job
End Do

End Sub

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top