For Windows Services, it cannot be started.

Source: Internet
Author: User
You may have encountered a situation where a windows service cannot be operated and cannot be stopped or started. I didn't know much about the nature of Windows Services. Today, I think I may have a hard time. Let me show you more. I hope you can point out something wrong. Multithreaded Services

The service control manager (SCM) controls a service by sending service control events to the service's control handler routine. the service must respond to control events in a timely manner so that the SCM can keep track of the state of the service. also, the state of the service must match the description of its state that the SCM has es.

Due to this communication mechanic between a service and the SCM, you must be careful when using multiple threads in a service. when a service is being ucted to stop by the SCM, it must wait for all the threads to exit before reporting to the SCM that the service is stopped. otherwise, the SCM can become confused about the state of the service and might fail to shut down correctly.

The SCM needs to be notified that the service is responding to the stop control event and that progress is being made in stopping the service. the SCM will assume the service is making progress if the service responds (throughSetServiceStatus) Within the time (wait hint) specified in the previous callSetServiceStatus, And the check point is updated to be greater than the checkpoint specified in the previous callSetServiceStatus.

If the service reports to the SCM that the service has stopped before all threads have exited, it is possible that the SCM will interpret this as a contradiction. this might result in a state where the service cannot be stopped or restarted.

 

It turns out that the code design of the multi-threaded service is incomplete, which leads to the red section described above.

That explains why it is better to restart the operating system (the process that has not been exited is naturally gone, and the problem is naturally gone .)

 

As a programmer, I think I have also found a related solution to use a tool (Process Monitor or ProcessExplorer) to kill the thread. However, this is not an easy job. for average people, or simply restart the instance.

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.