Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Oldie (as opposed to a newbie) trying to write a Windows Service

Oldie (as opposed to a newbie) trying to write a Windows Service

Scheduled Pinned Locked Moved C#
question
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jbradshaw
    wrote on last edited by
    #1

    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.

    P P 2 Replies Last reply
    0
    • J jbradshaw

      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.

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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 the Wait method for the period of time that I want the thread to sleep. This way, if I need to stop processing, I just Pulse the Monitor 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.

      My blog | My articles | MoXAML PowerToys | Onyx

      1 Reply Last reply
      0
      • J jbradshaw

        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.

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        I tend to write Services using a System.Timers.Timer -- so all I really need to do each time is write an Elapsed handler.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups