Creating a service

K

K Viltersten

I see in the examples at MSDN that when a
service is created, Main method is still
there, as the code below shows. Why is it
there?! I'd expect OnStart to be the only
required entry point for a service.

public static void Main() {
System.ServiceProcess.
ServiceBase.Run(new UserService1());}
 
P

Pavel Minaev

K Viltersten said:
I see in the examples at MSDN that when a
service is created, Main method is still
there, as the code below shows. Why is it
there?! I'd expect OnStart to be the only
required entry point for a service.

A service application is still a Windows .exe, and as such its entry point
is Main. It actually becomes a service process only after it registers
itself with the Service Control Manager, which is what ServiceBase.Run does.
 
K

K Viltersten

Got it, thanks.

In that case, i wonder why i need to
install the service. If the registration
is done in Main, it seems superfluous to
to that using installutil.exe as well.

What do i miss?
 
P

Pavel Minaev

K Viltersten said:
Got it, thanks.

In that case, i wonder why i need to
install the service. If the registration
is done in Main, it seems superfluous to
to that using installutil.exe as well.

What do i miss?

Registration of the specific running _process_ as a service is done in Main,
not of the executable. You still need to register the executable for it to
appear in the list of services.
 
K

K Viltersten

Got it, thanks.
Registration of the specific running _process_ as a service is done in
Main, not of the executable. You still need to register the executable for
it to appear in the list of services.

Got it, thanks!

Hey, how come my post went top-posted?!
It was unintentional, sorry...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top