如何调试在Init()方法失败的Windows服务 [英] How to debug windows service which fails in Init() method

查看:158
本文介绍了如何调试在Init()方法失败的Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows服务,在Init()方法中失败,并引发一些异常,所以我只能通过查看事件日志来检查错误是什么。我想调试Windows服务,但问题是我可以附加调试器,只有当服务正在运行,在我的情况下,它仅在Init()方法失败。任何想法?

解决方案

您可以编程地将调试器作为函数中的第一行附加:

  Debugger.Launch(); 

添加使用语句后:

 使用System.Diagnostics; 


I have a windows service which fails in Init() method and throws some exception , so only way for me to check what the error is by looking at the event log. I want to debug the windows service, but the problem is that i can attach debugger only when service is rnning, in my case it fails in Init() method only. Any idea ?

解决方案

you can programatically attach the debugger as the first line in the function:

Debugger.Launch ();

after adding the using statement:

using System.Diagnostics;

这篇关于如何调试在Init()方法失败的Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆