I am new to Windows services, so please forgive the main topic of this post.
I was instructed to update an existing service and you had some questions about how they work and continue to work in the background. I suppose some kind of cycle usually plays a game, 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 short, this service creates a System.IO.FileSystemWatcher object in the InitializeComponent () section and installs an event handler for its generated event.
In the OnStart method of the service (), a thread is created and started. This loop chain points to the FileSystemWatcher object in a specific directory and sets various parameters and parameters for FileSystemWatcher. This is not an infinite while () loop in any way; it does some math, including the timeout value provided by the user and the wait time for sleep, but in any case it will eventually exit.
The FileSystemWatcher event handler, mentioned above, in turn places the newly created file that triggered the event into a thread-safe queue, then either creates a new one or uses an existing thread to process the file in the queue. The queue processing code uses a loop to check the queue and remove any items from it and process them. When there are no elements in the queue, the while loop ends and the method exits.
These event-generated files are quite small and far from each other, so I don’t see how any cycle will be so busy as to remain all the time. By this logic, the service should stop, or I think. But he never does, he always works.
Is there an invisible message pump in the Windows service that supports it until OnStop events or pauses are triggered?
Hope this makes sense and apologizes if my descriptions are not done. I would be happy to think again if you think this can help. Thanks for your explanation here.
source
share