【问题标题】:How to stop service from service thread using C++?如何使用 C++ 从服务线程停止服务?
【发布时间】:2014-01-18 13:40:35
【问题描述】:

如何使用 C++ 从服务线程停止服务?

服务线程运行条件 while 循环。当此条件为假时,服务线程退出循环。但即使我将服务状态设置为停止状态,它的状态仍显示为“已启动”。

    Example:

    flag = 0
VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv)
{
// Register ServiceCtrlHandler
//  
....
.... 

 startService();
}
    void startService()
    {
    while(!flag)
    {
    if(!<condition>)
    {
     flag = 1;
    }
    }
    SetServiceStatus(<..>) // call to win32 API to update Service status to Stopped
    }

【问题讨论】:

  • 您需要展示更多内容才能获得帮助。

标签: c++ windows service


【解决方案1】:

您在示例中提到的 ServiceCtrlHandler 将处理控制请求并最终设置状态。

请关注The Complete Service Sample on MSDN,了解处理控制请求调度线程与服务主线程的交互。

另请参阅Writing a ServiceMain FunctionWriting a Control Handler Function

【讨论】:

  • 感谢您提供链接。我会通过它们。
猜你喜欢
  • 1970-01-01
  • 2020-01-23
  • 1970-01-01
  • 2011-02-17
  • 2012-05-25
  • 1970-01-01
  • 1970-01-01
  • 2020-07-01
  • 2019-06-18
相关资源
最近更新 更多