470,602 Members | 1,560 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,602 developers. It's quick & easy.

Windows Service and the "RegisterServiceCtrlHandlerEx" function

Hello Group,

I'm writting a Windows Services under C# to get some USB events. Because the ServiceBase class does not supports the SERVICE_CONTROL_DEVICEEVENT handler, I'm using P/Invoke to call the RegisterServiceCtrlHandlerEx funtion, using a callback to manage the needed handler. The invoke looks ok, it works.

The problem is when the services stops. My callback function receives the SERVICE_CONTROL_STOP handler but the function don't return. The Services Control shows an Error like: "The Services "myService" could not be stopped". The Service did not returned an error code.

If i hook my debug code to the service and try to stop the service again after the Error Message. I get the cursor in the Dispose function.

I think that with the calling of the ...Ex function, I have to do something more than to "return 0" when the SERVICE_CONTROL_STOP handler is received, .. Know somebody what should it be?
Thanks in advance.

--

KW
Nov 5 '07 #1
1 5007
Already found. I have to call the ServiceBase.Stop() when receiving the SERVICE_CONTROL_STOP in the HandlerEx callback funtion. Now is all ok.. nevertheless thanks .

KW.
"McKool" <ke*****@peak-system.comschrieb im Newsbeitrag news:uH**************@TK2MSFTNGP02.phx.gbl...
Hello Group,

I'm writting a Windows Services under C# to get some USB events. Because the ServiceBase class does not supports the SERVICE_CONTROL_DEVICEEVENT handler, I'm using P/Invoke to call the RegisterServiceCtrlHandlerEx funtion, using a callback to manage the needed handler. The invoke looks ok, it works.

The problem is when the services stops. My callback function receives the SERVICE_CONTROL_STOP handler but the function don't return. The Services Control shows an Error like: "The Services "myService" could not be stopped". The Service did not returned an error code.

If i hook my debug code to the service and try to stop the service again after the Error Message. I get the cursor in the Dispose function.

I think that with the calling of the ...Ex function, I have to do something more than to "return 0" when the SERVICE_CONTROL_STOP handler is received, .. Know somebody what should it be?
Thanks in advance.

--

KW
Nov 5 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.