Hello
I'm rather new to this with windows service.
I want to get a better understanding because I must use it if I don't want
to use a console application-
I have three important methods below. These are main, constructor for the
service class and a method called OnStart.
I'm from Sweden so I have tried to translate the name on dialog that I use
to start a windows service.
I start the service from
Start->Controllpanel->administratortool->KomponentService
When you start a service from dialog KomponentService the following happens.
You may correct me if I have wrong.
1. Main is always started first.
2. The class is instansiated which means that the constructor is called.
3.The constructor is executing and finally finishes
4.When the constructor has finishes the service control manager(SCM) calls
OnStart
Is this sequence correct or is it completely wrong.
Here is my main for the service project.
*****************************
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new
Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
MyNewService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}
Here is the Constructor
******************
public MyNewService()
{
InitializeComponent();
if(!System.Diagnostics.EventLog.SourceExists("DoDy LogSourse"))
System.Diagnostics.EventLog.CreateEventSource("DoD yLogSourse",
"DoDyLog");
eventLog1.Source = "DoDyLogSourse";
// the event log source by which
// the application is registered on the computer
eventLog1.Log = "DoDyLog";
}
Here I have the OnStart
******************
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("my service started");
}
//Tony