Continual Process in a Windows Service

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

Guest

Hello
I see that Windows Services are suppose to be able to run in their own background process. I can create simple Services based on the MSDN walkthrough, and get the OnStart/OnStop methods to work fine. But these are only triggered if the user manually goes into Component Services Manager and Starts/Stops the process - i.e. they don't continually run in the background. (Clicking either process puts the server on hold until that method finishes)

Can anyone tell me how to have a Service do a continual process in the background, such as writing a file to the c:\temp directory every 5 seconds

Thanks
Larry
 
Sure. Use a Timer. The timer is initialized in the OnStart method, and you
create an event handler for the elapsed event of the timer. The event
handler will run every time the interval elapses.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

Larry said:
Hello,
I see that Windows Services are suppose to be able to run in their own
background process. I can create simple Services based on the MSDN
walkthrough, and get the OnStart/OnStop methods to work fine. But these are
only triggered if the user manually goes into Component Services Manager and
Starts/Stops the process - i.e. they don't continually run in the
background. (Clicking either process puts the server on hold until that
method finishes).
Can anyone tell me how to have a Service do a continual process in the
background, such as writing a file to the c:\temp directory every 5 seconds?
 
normally on onstart you start a background thread that implements the
service. when you detect onstop, you stop the thread. you can configure the
service to autostart on bootup.

-- bruce (sqlwork.com)


Larry said:
Hello,
I see that Windows Services are suppose to be able to run in their own
background process. I can create simple Services based on the MSDN
walkthrough, and get the OnStart/OnStop methods to work fine. But these are
only triggered if the user manually goes into Component Services Manager and
Starts/Stops the process - i.e. they don't continually run in the
background. (Clicking either process puts the server on hold until that
method finishes).
Can anyone tell me how to have a Service do a continual process in the
background, such as writing a file to the c:\temp directory every 5 seconds?
 
Back
Top