The request is so incorrect! Please see my comment to the question. If you think that any foolishness posted on the Web makes sens, it can become a huge problem for you.
Also, the whole idea of having the service to poll any condition on periodic basic is wrong. So, first thing I would say is: you don't need such "service". You waste CPU time on checking up something when nothing happens; at the same time, you can easily miss the event, because someone can change your registry between your polls. You are doing something which hardly can make any sense. Perhaps if you explain why doing so, you can get a chance for some reasonable advice.
[EDIT; in connection to the follow-up question:]
The problem is not a search language, the problem is polling, which is always bad, even in simpler cases; I explained a part of it above.
For your understanding of the polling (pull vs push), please see:
http://en.wikipedia.org/wiki/Push_technology[
^],
http://en.wikipedia.org/wiki/Pull_technology[
^].
In particular, this class provides a benefit of the push approach:
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[
^].
You subscribe to a certain class of events on the file system, and all modifications are pushed to your handler code.
I don't say this class could be a best solution for you, it's more to give you the idea. I may or may not know the ultimate solution about the Registry issue; it depends on what you want to achieve, exactly. Why doing so?
Anyway, is you really need to detect registry changes, you need to use the push technology. One way to achieve this is subscribing to the events using WMI. Please see:
http://msdn.microsoft.com/en-us/library/aa393035.aspx[
^].
[END EDIT]
As to the stopping a service by human, the solution is trivial. In your implementation of the class
System.ServiceProcess.ServiceBase
, you can handle the Stop even by overriding the virtual
OnStop
method:
http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicebase.onstop.aspx[
^].
As simple as that. Problem solved.
—SA