471,337 Members | 948 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

An easy question about windows service

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

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

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()
if(!System.Diagnostics.EventLog.SourceExists("DoDy LogSourse"))
System.Diagnostics.EventLog.CreateEventSource("DoD yLogSourse",

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");
Sep 19 '07 #1
0 1037

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David Sugar | last post: by
6 posts views Thread by Julian McMaster | last post: by
4 posts views Thread by Water Cooler v2 | last post: by
reply views Thread by Kürşat | last post: by
3 posts views Thread by =?Utf-8?B?RGFuZGFuIFpoYW5n?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.