I came across a situation when I deployed the .NET service (C #) on a Win 2008R2 server. The service is dependent on MSMQ. When completing work, you must send some quick messages before sending. This works fine with manually triggered OnStop () events, but when the server shuts down and SCM calls OnShutdown (), I find that MSMQ is already turned off and my service cannot properly clear. For this I need only 2-5 seconds.
I understand (now) that service dependencies only apply to startup, so this does not help. Today I spent some time figuring out how to register my service, to accept new (starting from Vista) SERVICE_ACCEPT_PRESHUTDOWN events and work with the PreShutDownOrder function ( http://blogs.technet.com/b/askperf/archive/2008/ 02/04 / ws2008-service-shutdown-and-crash-handling.aspx ), but this is not supported in ServiceBase, as it is implemented in the structure, as far as I can tell.
I went down the path to manually set it using the SetServiceStatus () function, but it does not work.
_serviceHandle = this.ServiceHandle; SERVICE_STATUS serviceStatus = new SERVICE_STATUS(); serviceStatus.currentState = (int)State.SERVICE_RUNNING; serviceStatus.controlsAccepted = (int)(ControlsAccepted.SERVICE_ACCEPT_PRESHUTDOWN | ControlsAccepted.SERVICE_ACCEPT_STOP); serviceStatus.waitHint = 0; serviceStatus.checkPoint = 0; bool setStatus = SetServiceStatus(_serviceHandle, ref serviceStatus); int error = Marshal.GetLastWin32Error();
This returns error status 13 when calling GetLastError();
Any ideas on how to connect to pre-launch events?
source share