Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Errors regarding Windows Services

Status
Not open for further replies.

DanielLCC

Programmer
Feb 16, 2006
8
US
I have two questions:

First, I was working on debugging a service I had just written and getting really frustrated because nothing I tried seemed to be fixing a relatively simple problem. Eventually I figured out that VB .net hadnt been building new .exe files at all. I tested this by deleting the .exe from the bin folder and rebuilding, and it didnt help. I worked around this by copy-and-pasting the code into a new file. Does anyone know why this happens?

Second, Once I had the service completely running I found that my controller application was having problems with its servicecontroller. If the service was stopped it wouldnt be able to start it and if I tried to stop it again it would give me this error: "Cannot start service service1 on computer '.'"

I had had this error before when I tried to stop the service when it was already stopped so I added this code:

If (ServiceController1.Status =
ServiceProcess.ServiceControllerStatus.Running.Running

Or ServiceController1.Status = ServiceProcess.ServiceControllerStatus.StartPending)

And ServiceController1.CanStop = True Then

ServiceController1.Stop()
End If
 
How much stuff are you doing in the OnStart event? Because this event is called by the ServiceControlManager (SCM, pronounced "scum"), and you're running on it's thread. Because the SCM has better things to be doing, it only gives you 30 seconds to get your service started. If you take to long (like block on an I/O call), it will mark you unresponsive, and stop the service.

Typically, in your OnStart event code you would start a new worker thread, create a new ManualResetEvent object, and return. In the OnStop event, you would .Set() the ManualResetEvent object, which would then serve as an indication to your worker thread that it's time to close up shop.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Ok, That turned out to be the problem with starting the service, but now there are more problems. Now if I start the application and click start service it doesnt start the service (The servicecontroller is saying that it is already running) and when I click stop it gives me the "cannot stop service..." message again. Any clues on that?
 
nevermind, I just had to refresh the servicecontroller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top