Hello everyone,
For Windows Service, for example class Service1 is the main class of my service application, which derives from ServiceBase. I am wondering whether it is possible that two concurrent access to the following 3 cases?
1. the constructor of Service1;
2. OnStart method of Service1;
3. OnStop method of Service.
If yes, I need some synchronizaton control in them. If yes, in what situation the three methods will be called concurrently? We are able to start/stop the same service with different instances (processes) at the same time?
thanks in advance,
George
George GeorgePosted Apr 15, 2008, 4:33 AM
Hi Alan,
After some thinking, I have a further question. When multiple clients want to start the same instance at the same time? What will happen? OnStart will be invoked multiple times even if they are synchronized?
(my question is the same to express as, what will happen if a client wants to start a service, which is already started? by calling OnStart?)
regards,
George
George GeorgePosted Apr 15, 2008, 4:12 AM
Thanks Alan,
Question answered.
regards,
George
AlanPosted Apr 14, 2008, 10:54 AM
I don't think you need to worry about any of this George.
As far as I'm aware, only one instance of a windows service can exist at a time and constructors are always threadsafe in any case.
Also, it is the Service Control Manager (part of Windows) which is ultimately responsible for starting and stopping a service and I think it's therefore safe to assume that this won't be attempted concurrently by multiple threads.