是否可以在Visual Studio中调试Windows服务?
我用的代码就像
System.Diagnostics.Debugger.Break();
Run Code Online (Sandbox Code Playgroud)
但它给出了一些代码错误,如:
我收到两个事件错误:eventID 4096 VsJITDebugger和"服务没有及时响应启动或控制请求."
我想调试一个Windows服务,但它弹出一条错误消息说
无法从命令行或调试器启动服务.必须使用installutil.exe安装Windows服务,然后使用Server explorer,Windows服务管理工具或NET启动命令启动.
我真的不知道这个错误.....
是否可以在Windows服务中使用UnhandledException处理程序?
通常我会使用自定义构建的异常处理组件来执行日志记录,电话回家等.这个组件为System.AppDomain.CurrentDomain.UnhandledException添加了一个处理程序,但据我所知,这并没有实现赢得Windows服务的任何东西所以我最终在我的2(或4)个服务入口点中使用了这种模式:
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Try
MyServiceComponent.Start()
Catch ex As Exception
'call into our exception handler
MyExceptionHandlingComponent.ManuallyHandleException (ex)
'zero is the default ExitCode for a successfull exit, so if we set it to non-zero
ExitCode = -1
'So, we use Environment.Exit, it seems to be the most appropriate thing to use
'we pass …Run Code Online (Sandbox Code Playgroud)