Windows Services Architecture from .Net perspective

Several Windows services can share a single process. In C #, they start as:

ServiceBase.Run(new MyService1(), new MyService2()); 

The run method call blocks the thread in which main() is executed. At the same time, service events are being processed. So where do they run?

Do they use an asynchronous procedure call in the "main" process, which is not just blocked, but in a waiting state? If so, process sharing for several services has a performance penalty. Do handlers work in separate threads? Are they executed outside the process containing the Run() call?

+8
c # windows winapi service
source share
2 answers

On Windows, several services can share a single process using the SERVICE_WIN32_SHARE_PROCESS service type .. NET must use this service type to register multiple services in a single process on Windows.

Each registered service has a name and its own address of the entry point represented by the SERVICE_TABLE_ENTRY ..NET structure. It must build SERVICE_TABLE_ENTRY for each service passed to the ServiceBase.Run method and call the StartServiceCtrlDispatcher function with this data.

To receive notifications about the status of a service, an entry point ( ServiceMain implemented by the ServiceBase class) must call RegisterServiceCtrlHandlerEx to receive notifications. These notifications are sent using APC. As a side note, the NotifyServiceStatusChange API also uses APC.

0
source share

What you probably followed is the architecture of Windows services and how service applications integrate into them.

This article on MSDN already has a very good article that can be found here.

This not only explains how Windows interacts with services, how the services database works (at least in part).

The article also explains how the operating system services work, and gives some hint about the hosting services in IIS (Internet Information Services).

0
source share

All Articles