Creating a service

  • Thread starter Thread starter K Viltersten
  • Start date Start date
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());}
 
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.
 
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?
 
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.
 
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...
 
Back
Top