8

Several windows services can share one process. In C# they will start as:

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

The call of run method blocks the thread where main() executes. At the same time events of services are handled. So where are they executed?

Do they use Asynchronous Procedure Call in the "main" process that is not just blocked but is in alertable waiting? If it's so, the sharing a process for multiple services has drawback in performance. Do handlers run in separate threads? Are they executed outside of the process containing the Run() call?

3

2 Answers 2

0

In Windows, multiple services can share a single process by using the SERVICE_WIN32_SHARE_PROCESS service type. .NET have to use this service type to register multiple services in a single process on Windows.

Every registered service has a name and a native entry point address represented by the SERVICE_TABLE_ENTRY structure. .NET shall construct a SERVICE_TABLE_ENTRY for each service passed to the ServiceBase.Run method, and call StartServiceCtrlDispatcher function with these information.

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

0

What you probably are after is the windows service architecture and how service applications are integrated in them.

There is already a very good article on that topic in the MSDN, which can be found here.

It not only explains how Windows interacts with services, how the services database works (at least partly).

The article also explains how operating system services work and gives some hint on hosting services in the IIS (Internet information services).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.