Continual Process in a Windows Service

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Larry

    Continual Process in a Windows Service

    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
  • Kevin Spencer

    #2
    Re: Continual Process in a Windows Service

    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" <anonymous@disc ussions.microso ft.com> wrote in message
    news:FBE91C29-A161-4955-8ADB-6D82FEFA328B@mi crosoft.com...[color=blue]
    > Hello,
    > I see that Windows Services are suppose to be able to run in their own[/color]
    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).[color=blue]
    >
    > Can anyone tell me how to have a Service do a continual process in the[/color]
    background, such as writing a file to the c:\temp directory every 5 seconds?[color=blue]
    >
    > Thanks,
    > Larry[/color]


    Comment

    • bruce barker

      #3
      Re: Continual Process in a Windows Service

      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" <anonymous@disc ussions.microso ft.com> wrote in message
      news:FBE91C29-A161-4955-8ADB-6D82FEFA328B@mi crosoft.com...[color=blue]
      > Hello,
      > I see that Windows Services are suppose to be able to run in their own[/color]
      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).[color=blue]
      >
      > Can anyone tell me how to have a Service do a continual process in the[/color]
      background, such as writing a file to the c:\temp directory every 5 seconds?[color=blue]
      >
      > Thanks,
      > Larry[/color]


      Comment

      Working...