The problem is that you do something in OnStart() of the Windows service and
the something keppes going on until some conditions matched. So, until the
conditions matched, the windows service will never be fully started (i,e.
not able to provide service).
According to your previous post, I think you are using Windows Service in a
wrong way. If you want a windows service do something, you do it AFTER the
service is started. In OnStart() you do initializing (i.e, prepare the
Windows service for the job you want it to do). For example, it the Win
Service is used for access data in database, you do not put the main data
access process in OnStart(), but you can write some code in OnStart() to get
database access settings, such as read ConnectionString from config. file or
from registry. Of cource, the logic in OnStart() can be more complecated
than that. Then, you must handle all possible exceptions in order for the
service can be started, and you also have to have a way to deal situation
like, if particaular initialization in OnStart() fails and the service
started anyway, what is the impact on the job you want the service to do...
The other thing you need to remember is, Wndows Service itself does nothing.
It provides a hosting environment for certain objects to run inside it. Most
.NET books use FileWatcher as the object hosted by a Windows Service.
Typically, you can host a Remoting object in Windows Service to do what you
want (accessing database...).
Stephen said:
Thanks Alvin,
Question:
How do I stop or Pause the service? as the SCM status is always "Starting"
and "Stop" and "Pause" is never enabled.
Here's and eg of what I have experimented with:
1. Created a Windows Service and have used "OnStart" and "OnStop"
2. OnStart (Just for kicks) insert records into a testDB until conditions
match
3. OnStop delete all records from testDB.
Problem:
OnStart starts the service and contiunues forever... the condition does
not
set itself to "Started", so the only way I can stop is to kill the process
Any suggestions,
Thanks again,
Stephen
Alvin Bruney - ASP.NET MVP said:
build a windows service application to monitor the process - these are
called watch dog applications. You don't need to programmatically build a
stop or pause routine into the application because that type of
functionality is typically handled by the windows control manager.
A console based application is less reliable because it isnt
automatically
started when windows restarts
--
Regards,
Alvin Bruney [MVP ASP.NET]
[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @
www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------
Hi all,
I am confused as to what kind of application to develop. I have to create
an
application thats like a "Engine" which continously monitors a DB or
whatever. It has to work even if the user logoff as this engine feeds some
other application.
I tried creating a Windows service that runs continously but the status
shows "Starting" and i cant "Stop" or "Pause" and was suggested by one
BravesCharm that "Status does not change as the service never
notifies
the
SCM that everything started OK" which makes sense.
Is there a way for windows service to start some other application?
is
yes
then how can i stop it from this windows service?
Please do give me suggestions on how to achieve this.
Thanks,
Stephen