473,379 Members | 1,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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 5228
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Adam Clauss | last post by:
I have a C# Windows Service running as the NetworkService account because it needs to access a network share. As part of the service's initialization, I want the service to terminate, if an...
11
by: Frank Rizzo | last post by:
Hello, My c# based windows service takes a while to dispose. I have to release bunch of resources all over the place and unfortunately it can take 20-40 seconds before I can cleanly exit. ...
3
by: gregory_may | last post by:
According to this article, I cant change "CanStop" on the fly!!! ...
7
by: Sunil Varma | last post by:
Hello all, I wrote a Windows Service in VC.NET 2005 I want to debug the solution. I tried as mentioned in the following link. ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.