简体   繁体   中英

Prevent windows service from stopping during debug

I'm developing an extension for the product which in fact is windows service. I'm attaching to the service from Visual Studio but after couple minutes of debugging the service stops working so I need to begin debugging from scratch or do everything fast.

I'm pretty sure that the soultion should exist. Can anybody help me?

I don't think attaching a debugger to a live service is a good idea; the service manager expects services to respond promptly to status requests and control signals, which the service can't do if it is being single-stepped or otherwise interfered with.

The usual procedure for debugging services is for the executable to have a command-line option that makes it run as a regular application, with some mechanism for emulating service control signals if necessary. You can then debug it in the same way you would debug any other application.

An alternative if the debugging really must be done on the live service might be to run the service in a virtual machine (or a separate physical machine) and use a kernel debugger.

There are two main reason for Windows Service to stop

1) it finishes their job and execute your code that's means your code not into timer, infinite loop or do backgroundwork

2) there is exception occurs that makes the service sopped working that's mean you need to put a big try\\catch in your whole code to trace where is the error and prevent the service from stopping

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM