Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6604889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:13:02+00:00 2026-05-25T19:13:02+00:00

I have created a Windows Service in VB.NET (VS2010) that executes a certain task

  • 0

I have created a Windows Service in VB.NET (VS2010) that executes a certain task every minute. When the service is being stopped, either manually by the user, or when the system is rebooted, what can I do to make sure the task is being finished properly before the service is actually terminated?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:13:03+00:00Added an answer on May 25, 2026 at 7:13 pm

    You should override the Service’s OnStop event.

     ' when stopping release the resources
     Protected Overrides Sub OnStop()
        ReleaseYourObjects()
     End Sub
    

    Here you should finish your task and release all resources that need to be released.

    The constructor of the service will not be called again when it’s restarted. Because of this, you should not use the constructor to perform startup processing, rather use the OnStart() method to handle all initialization of your service, and OnStop() to release any resources.

    Reduced to your needs, it might be sufficient to stop the timer so that it could simply be restarted in OnStart:

    Me.ServiceTimer.Change(Timeout.Infinite, Timeout.Infinite)
    

    If your task is started from it’s own thread, you can ensure that it will be finished properly.

    When it’s instead running in the main-thread and…

    … when the Windows Service Control Manager (SCM) calls the
    OnStart(), OnStop(), OnPause(), or OnContinue() method, you
    only have ~60 sec before you must return. If you do not return within
    this time, then the SCM will mark that service as not responding.
    After a while, it can out right kill the process you are running in.
    If you need more time to process things during these methods, you can
    call the RequestAdditionalTime() method and tell the SCM that things
    are talking a bit longer that it expects. (See the OnStop() method in
    the example above.)

    Read more: http://www.codeproject.com/KB/system/LexnnWinService.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a .NET Windows Service (in VS2010) that needs to: Access shared
I have created a .NET Windows Service which performs certain actions and generates reports.
I have created a Windows Service in VB.net for building xML from a database.
I have created a simple windows service that periodically checks a remote database via
We have created a WCF service hosted in a windows service that handles Authentication
I have created a Windows Forms application in .NET 2 using C# that runs
I have created a WCF service that is hosted using windows service. The windows
We have a Windows Service created in .Net 4.0, the services parses large text
I have a Windows Service created in .NET 4. I need to access a
I created a .NET windows service that installs without any issues on the dev

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.