Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. While going from Paused to Stopped, the Service Hangs at Stopping

While going from Paused to Stopped, the Service Hangs at Stopping

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SunilKrSingh
    wrote on last edited by
    #1

    While going from Paused to Stopped the Service Status Hangs at Stopping, eventually timing out and receiving an error message. Error 1053: The service did not respond to the start or control request in a timely fashion. Following code is causing the service to go into not responding state when going from paused to Stopped state. Can anyone plz help me in finding out whats wrong with the code? When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way? VOID Handler (DWORD controlCode) { DWORD currentState = 0; BOOL success; switch(controlCode) { // Stop the service case SERVICE_CONTROL_STOP: { success = SendStatusToSCM(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000); } break; // Pause the service case SERVICE_CONTROL_PAUSE: if (runningService && !pauseService) { // Tell the SCM what's happening success = SendStatusToSCM( SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000); pauseService = TRUE; SuspendThread(threadHandle); currentState = SERVICE_PAUSED; } break; } BOOL SendStatusToSCM (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) { BOOL success; SERVICE_STATUS serviceStatus; // Fill in all of the SERVICE_STATUS fields serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; serviceStatus.dwCurrentState = dwCurrentState; // If in the process of doing something, then accept // no control events, else accept anything if (dwCurrentState == SERVICE_START_PENDING) serviceStatus.dwControlsAccepted = 0; else serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN; // if a specific exit code is defined, set up // the win32 exit code properly if (dwServiceSpecificExitCode == 0) serviceStatus.dwWin32ExitCode = dwWin32ExitCode; else serviceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR; serviceStatus.dwServiceSpecificExitCode = dwServiceSpecificExitCode; serviceStatus.dwCheckPoint = dwCheckPoint; serviceStatus.dwWaitHint = dwWaitHint; // Pass the status record to the SCM success = SetServiceStatus (serviceStatusHandle, &serviceStatus); return success; }

    M M J 3 Replies Last reply
    0
    • S SunilKrSingh

      While going from Paused to Stopped the Service Status Hangs at Stopping, eventually timing out and receiving an error message. Error 1053: The service did not respond to the start or control request in a timely fashion. Following code is causing the service to go into not responding state when going from paused to Stopped state. Can anyone plz help me in finding out whats wrong with the code? When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way? VOID Handler (DWORD controlCode) { DWORD currentState = 0; BOOL success; switch(controlCode) { // Stop the service case SERVICE_CONTROL_STOP: { success = SendStatusToSCM(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000); } break; // Pause the service case SERVICE_CONTROL_PAUSE: if (runningService && !pauseService) { // Tell the SCM what's happening success = SendStatusToSCM( SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000); pauseService = TRUE; SuspendThread(threadHandle); currentState = SERVICE_PAUSED; } break; } BOOL SendStatusToSCM (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) { BOOL success; SERVICE_STATUS serviceStatus; // Fill in all of the SERVICE_STATUS fields serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; serviceStatus.dwCurrentState = dwCurrentState; // If in the process of doing something, then accept // no control events, else accept anything if (dwCurrentState == SERVICE_START_PENDING) serviceStatus.dwControlsAccepted = 0; else serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN; // if a specific exit code is defined, set up // the win32 exit code properly if (dwServiceSpecificExitCode == 0) serviceStatus.dwWin32ExitCode = dwWin32ExitCode; else serviceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR; serviceStatus.dwServiceSpecificExitCode = dwServiceSpecificExitCode; serviceStatus.dwCheckPoint = dwCheckPoint; serviceStatus.dwWaitHint = dwWaitHint; // Pass the status record to the SCM success = SetServiceStatus (serviceStatusHandle, &serviceStatus); return success; }

      M Offline
      M Offline
      Malli_S
      wrote on last edited by
      #2

      When you change your service status from pause to stop, does your service main function really changing the state or exiting ?

      [Delegates]      [Virtual Desktop]      [Tray Me !]
      -Malli...! :rose:****

      1 Reply Last reply
      0
      • S SunilKrSingh

        While going from Paused to Stopped the Service Status Hangs at Stopping, eventually timing out and receiving an error message. Error 1053: The service did not respond to the start or control request in a timely fashion. Following code is causing the service to go into not responding state when going from paused to Stopped state. Can anyone plz help me in finding out whats wrong with the code? When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way? VOID Handler (DWORD controlCode) { DWORD currentState = 0; BOOL success; switch(controlCode) { // Stop the service case SERVICE_CONTROL_STOP: { success = SendStatusToSCM(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000); } break; // Pause the service case SERVICE_CONTROL_PAUSE: if (runningService && !pauseService) { // Tell the SCM what's happening success = SendStatusToSCM( SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000); pauseService = TRUE; SuspendThread(threadHandle); currentState = SERVICE_PAUSED; } break; } BOOL SendStatusToSCM (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) { BOOL success; SERVICE_STATUS serviceStatus; // Fill in all of the SERVICE_STATUS fields serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; serviceStatus.dwCurrentState = dwCurrentState; // If in the process of doing something, then accept // no control events, else accept anything if (dwCurrentState == SERVICE_START_PENDING) serviceStatus.dwControlsAccepted = 0; else serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN; // if a specific exit code is defined, set up // the win32 exit code properly if (dwServiceSpecificExitCode == 0) serviceStatus.dwWin32ExitCode = dwWin32ExitCode; else serviceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR; serviceStatus.dwServiceSpecificExitCode = dwServiceSpecificExitCode; serviceStatus.dwCheckPoint = dwCheckPoint; serviceStatus.dwWaitHint = dwWaitHint; // Pass the status record to the SCM success = SetServiceStatus (serviceStatusHandle, &serviceStatus); return success; }

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        I'm not even going to bother trying to read that unformatted code, but have you debugged it in the debugger? You can attach to service processes and step through and use breakpoints...

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        1 Reply Last reply
        0
        • S SunilKrSingh

          While going from Paused to Stopped the Service Status Hangs at Stopping, eventually timing out and receiving an error message. Error 1053: The service did not respond to the start or control request in a timely fashion. Following code is causing the service to go into not responding state when going from paused to Stopped state. Can anyone plz help me in finding out whats wrong with the code? When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way? VOID Handler (DWORD controlCode) { DWORD currentState = 0; BOOL success; switch(controlCode) { // Stop the service case SERVICE_CONTROL_STOP: { success = SendStatusToSCM(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000); } break; // Pause the service case SERVICE_CONTROL_PAUSE: if (runningService && !pauseService) { // Tell the SCM what's happening success = SendStatusToSCM( SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000); pauseService = TRUE; SuspendThread(threadHandle); currentState = SERVICE_PAUSED; } break; } BOOL SendStatusToSCM (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) { BOOL success; SERVICE_STATUS serviceStatus; // Fill in all of the SERVICE_STATUS fields serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; serviceStatus.dwCurrentState = dwCurrentState; // If in the process of doing something, then accept // no control events, else accept anything if (dwCurrentState == SERVICE_START_PENDING) serviceStatus.dwControlsAccepted = 0; else serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN; // if a specific exit code is defined, set up // the win32 exit code properly if (dwServiceSpecificExitCode == 0) serviceStatus.dwWin32ExitCode = dwWin32ExitCode; else serviceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR; serviceStatus.dwServiceSpecificExitCode = dwServiceSpecificExitCode; serviceStatus.dwCheckPoint = dwCheckPoint; serviceStatus.dwWaitHint = dwWaitHint; // Pass the status record to the SCM success = SetServiceStatus (serviceStatusHandle, &serviceStatus); return success; }

          J Offline
          J Offline
          jschell
          wrote on last edited by
          #4

          SunilKrSingh wrote:

          When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way?

          No. Those two values are intended for different usages. I am not sure how you decided they were equivalent. You use SERVICE_STOP_PENDING, while you are doing work to stop a service. Such as if you have a thread that you must wait to complet. You need to use the value SERVICE_STOPPED when the service is stopped. Just before you exit. And the reason it appears to work is because SERVICE_CONTROL_STOP and SERVICE_STOPPED both resolve to the same integer value.

          S 1 Reply Last reply
          0
          • J jschell

            SunilKrSingh wrote:

            When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way?

            No. Those two values are intended for different usages. I am not sure how you decided they were equivalent. You use SERVICE_STOP_PENDING, while you are doing work to stop a service. Such as if you have a thread that you must wait to complet. You need to use the value SERVICE_STOPPED when the service is stopped. Just before you exit. And the reason it appears to work is because SERVICE_CONTROL_STOP and SERVICE_STOPPED both resolve to the same integer value.

            S Offline
            S Offline
            SunilKrSingh
            wrote on last edited by
            #5

            I got the root cause of the issue. Pausing the service is causing the service thread to be suspended with the statement SuspendThread(threadHandle); So an attempt to stop the service from a paused state with SERVICE_STOP_PENDING was failing with error Error 1053: The service did not respond to the start or control request in a timely fashion. I had to resume the service thread before the stopping the service. Thanks, Sunil

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups