It is working fine for me. I am using Microsoft Visual Studio Community 2022.
Did you download and extract the zip file? Did VS perform an upgrade on the project?
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have followed the link for my C++ services
https://www.codeproject.com/Articles/499465/Simple-Windows-Service-in-Cplusplus
if I stop the services in service window
then,
it passes the ServiceCtrlHandler successfully
VOID WINAPI ServiceCtrlHandler (DWORD CtrlCode)
{
switch (CtrlCode)
{
case SERVICE_CONTROL_STOP :
if (g_ServiceStatus.dwCurrentState != SERVICE_RUNNING)
break;
/*
* Perform tasks necessary to stop the service here
*/
g_ServiceStatus.dwControlsAccepted = 0;
g_ServiceStatus.dwCurrentState = SERVICE_STOP_PENDING;
g_ServiceStatus.dwWin32ExitCode = 0;
g_ServiceStatus.dwCheckPoint = 4;
if (SetServiceStatus (g_StatusHandle, &g_ServiceStatus) == FALSE)
{
OutputDebugString(_T(
"My Sample Service: ServiceCtrlHandler: SetServiceStatus returned error"));
}
// This will signal the worker thread to start shutting down
SetEvent (g_ServiceStopEvent);
break;
default:
break;
}
}
and then
it hangs in stopping
It is working fine for me. I am using Microsoft Visual Studio Community 2022.
Did you download and extract the zip file? Did VS perform an upgrade on the project?
yes you are right it is working when it is single thread but in case of multithreading?
In my function I am using multithreading
https://learn.microsoft.com/en-us/answers/questions/944374/hang-in-stopping.html
I am using vs 2019
multithreading: is stopping and hang image
singlethread is working as expected