VS 2010 Windows Services-VBForums
Results 1 to 2 of 2

Thread: Windows Services

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2008
    Location
    Scotland
    Posts
    63

    Windows Services

    Good afternoon

    In Visual Basic, I've build a suite of Windows Services to run various repetitive tasks throughout the day. I've also built a maintenance service which, at predefined times each day, stop and restart the other services so that they remain fresh.

    The maintenance service (which I have to confess to being rather proud of) interrogates the appropriate service's controller status. If it finds that the status is either "Running" or "StartPending" then it issues a stop command, before Sleeping for 60 seconds. It then interrogates the status again and issues a Start command if the status is either "Stopped" or "StopPending".

    Everything is working really well, but I've noticed that if a service has been changed so that its Startup Type is disabled, it generates an exception when it issues the Start command. Whilst this isn't necessarily a problem, it would mean that the exception log is being filled with phantom exceptions, when there might be a very good reason for a service having been disabled.

    Is there any way of interrogating the startup type of a service just prior to that Start command being fired, so that I can decide whether or not to even try the Start?

    TIA

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,309

    Re: Windows Services

    I don't have an example in vb.net but if you don't mind reviewing an easy to read C# service then check this one out.

    What I do is OnStart get the mode e.g. Interval or Daily from App.config in a separate method call within another class. From here a Timer is setup with a delegate setup with the time for execution. Once the intended code finishes executing the service disposes of the Timer then sets it back up again in a continuous cycle. In any event, not sure if this is helpful or not to you.

    Lastly, in the link above I have a GUI for starting/stopping and pausing the service which allows for debugging too.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.