Continual Process in a Windows Service

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
 
K

Kevin Spencer

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?
 
B

bruce barker

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?
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top