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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Service

Status
Not open for further replies.

stardv

Technical User
May 27, 2004
33
US

I have a question about onStart() method with windows service. Do I put main execution code in onStart() method? It looks like it will not start until it executes all code within onStart() method. I have a thread started in the onStart() method and it is infinite so Service never starts. Where I can place my start thread code in order to be able to start the service and have the thread running.

Many thanks
 
The OnStart event gets run by the SCM (service control manager), so you don't want to put any substantial code in there (otherwise the SCM will mark your service as being unresponsive). What you should do is start a thread, and have the lengthy initialization work being done in the thread callback.

In the example code at:
[tab]the static void Main acts as your OnStart event, and the static void ThreadProc is where your work would happen. The difference is you wouldn't use a call Join -- when the ThreadProc finishes it just goes away.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top