Oldie (as opposed to a newbie) trying to write a Windows Service
-
So I'm a programmer who's been programming for 20 years. I have written Windows services numerous times and need to do it again. There are things that my service code doesn't do (like run in console mode) that I'd like it to do. So does anybody have any code that I can steal that is the basis for a Windows service? I know I can create a new project as a Windows Service through VS2010 but was wondering if anybody has a basis I can use. Also - the premise I used was in the OnStart command, start a timer that would run a routine that would poll for things to do. The routine would never end and check, based on time, if something needs to be done. Is this still an appropriate method for doing a service or is there a better way? TIA - Jeff.
-
So I'm a programmer who's been programming for 20 years. I have written Windows services numerous times and need to do it again. There are things that my service code doesn't do (like run in console mode) that I'd like it to do. So does anybody have any code that I can steal that is the basis for a Windows service? I know I can create a new project as a Windows Service through VS2010 but was wondering if anybody has a basis I can use. Also - the premise I used was in the OnStart command, start a timer that would run a routine that would poll for things to do. The routine would never end and check, based on time, if something needs to be done. Is this still an appropriate method for doing a service or is there a better way? TIA - Jeff.
Jeff - when I create a service, I tend to use a form of background thread to run the processing. If I have something that I need to run periodically, I use a
Monitor
because I use theWait
method for the period of time that I want the thread to sleep. This way, if I need to stop processing, I justPulse
theMonitor
and shut it down."WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
So I'm a programmer who's been programming for 20 years. I have written Windows services numerous times and need to do it again. There are things that my service code doesn't do (like run in console mode) that I'd like it to do. So does anybody have any code that I can steal that is the basis for a Windows service? I know I can create a new project as a Windows Service through VS2010 but was wondering if anybody has a basis I can use. Also - the premise I used was in the OnStart command, start a timer that would run a routine that would poll for things to do. The routine would never end and check, based on time, if something needs to be done. Is this still an appropriate method for doing a service or is there a better way? TIA - Jeff.
I tend to write Services using a System.Timers.Timer -- so all I really need to do each time is write an Elapsed handler.