Oti*_*iel 1 .net c# debugging windows-services
我正在F5使用以下代码调试Windows服务(通过在Visual Studio 2010中点击):
在Program.cs文件中:
static void Main() {
if (!Environment.UserInteractive) {
// We are not in debug mode, startup as service
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new MyServer() };
ServiceBase.Run(ServicesToRun);
}
else {
// We are in debug mode, startup as application
MyServer service = new MyServer();
service.StartService();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
}
}
Run Code Online (Sandbox Code Playgroud)
在MyServer.cs文件中:
public void StartService() {
this.OnStart(new string[0]);
}
Run Code Online (Sandbox Code Playgroud)
在过去,我Debug.WriteLine("xxx")在所有服务代码中使用该行没有任何问题,但现在我注意到所有Debug.WriteLine()行都不再被调用.
当我使用Step Into(F11)调试时,我清楚地看到调试器跳过这些行- (因此,输出窗口上没有输出文本),而服务在"调试模式"下正确启动.
我不明白为什么Debug代码不会被调用.建议?
我在调试模式下构建我的解决方案(Define DEBUG constant已选中),但我注意到#if DEBUG ... #endif未被调用的代码被包围.这很奇怪......
似乎缺少Debug符号.
发生在我身上,这似乎有所帮助.
| 归档时间: |
|
| 查看次数: |
2160 次 |
| 最近记录: |