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

  • SEARCH
  • Home
  • 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 596183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:08:39+00:00 2026-05-13T16:08:39+00:00

I’m new to windows services, so pardon the basic nature of this post. I’ve

  • 0

I’m new to windows services, so pardon the basic nature of this post.

I’ve been tasked with updating an existing service and had some questions about how they work and keep running in the background. I assume a loop of some sort is usually in play, but in the case below I’m not sure how it works and why it doesn’t stop in a short amount of time.

In brief, this service creates a System.IO.FileSystemWatcher object in its InitializeComponent() section and establishes an event handler for its Created event.

In the service’s OnStart method(), a thread is created and started. This thread loops and instructs the FileSystemWatcher object to look at a particular directory, and establishes various settings and options for the FileSystemWatcher. It’s not an infinite while() loop by any means; it does some math involving a user supplied timeout value and a wait time for sleeping, but in every case it will exit eventually.

The FileSystemWatcher event handler referred to above, in turn, puts the newly created file that triggered the event onto a thread-safe queue, then either creates a new or uses an existing thread to process the queued file. The queue-processing code uses a loop to check the queue and remove any items from it and process them. When there are no items in the queue, the while loop ends and the method exits.

These file created events are pretty few and far between, so I can’t see how either loop would be so busy as to remain running all the time. By this logic the service should stop, or so I’d think. But it never does, it’s always running.

Is there some invisible message pump in a windows service that keeps it going until the OnStop or pause events are fired?

I hope this makes sense, and apologies if my descriptions didn’t. I’d be happy to elaborate further if you think it might help. Thanks for your explanations here.

  • 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-13T16:08:40+00:00Added an answer on May 13, 2026 at 4:08 pm

    You don’t need that loop.

    Consider your business class creating your FileSystemWatcher and signing for it’s events, and all other stuff your need.

    On ServiceBase.OnStart override, you’ll create an instance from your business class and to place it into a class level variable (a field, for instance).

    On ServiceBase.OnStop override, you’ll clean anything you need.

    And that’s it. You don’t need to deal with background threads or anything else.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.