Simon,
To put it simply, a Windows Service is an application that has some
predefined procedures so that the OS can control it (start/stop/pause). A
Windows Service should also not start doing anything (except initialization)
until it gets a start command, and it should run forever until it receives
pause/stop commands from the OS. If you use the Windows Service wizard in
VisualStudio, the functions are already created for you.
The service is run in it's own thread, but you still need to be friendly to
the other application running on the computer. Example, don't loop forever
waiting for a variable to change in order to wait for something to happen,
instead, using Mutexes or Thread.WaitforObject (not sure on exact function
name though). If you just loop waiting for a change, then that loop will eat
up 100% of the CPU time.
I've written a few windows services, and the hardest part about writing a
service is making it run forever (until it gets a stop/pause), without
causing interference while it's waiting for other things to happen at the
same time making it responsive, and pausable and stopable.
If you need some more help, let me know
Steve
"Simon Harvey" <si**********@the-web-works.co.uk> wrote in message
news:ud**************@TK2MSFTNGP10.phx.gbl...
Hi everyone,
I need to make a service that monitors a directory for changes in the
files contained within it. I have two questions:
1. I'm going to be using a FileSystemWatcher object to do the monitoring -
but do I need to somehow involve another thread to allow the service to do
other stuff as well, or is another thread created automatically when the
FileSystemMonitor object is created?
2. Because I'm creating a service, and not an application, do I need to
worry about threading at all? Is it possible that my service could try and
steal all the processors resources, or does the operating system
automatically give each service a shot of the processor such that I don't
have to worry about it?
Sorry, I'm a bit unkowledgeable in this area - I'm making an application
for my boss though and I don't want to arse it up! :-)
Thanks to nayone and everyone who can help
Kindest Regards
Simon