调试窗口服务 [英] debugging window service

查看:105
本文介绍了调试窗口服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要调试窗口服务。我应该怎么写在main(),使窗口服务调试。我使用C#开发窗口服务。

I want to debug window service. What should i write in main() to enable debugging in window service. I am developing window service using C#.

#if(DEBUG)
      System.Diagnostics.Debugger.Break();
      this.OnStart(null);
      System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
 #else
      ServiceBase.Run(this);
 #endif



我上面的代码段,但上线(这

i wrote above code segment but on line (this

推荐答案

我会做这样的:结果
在你的服务的的OnStart 方法顶部的调用添加到 Debugger.Break()

I would do it like this:
In your service's OnStart method add the call to Debugger.Break() at the top:

protected override void OnStart(string[] args)
{
    #if DEBUG
        Debugger.Break();
    #endif

    // ... the actual code
}

这篇关于调试窗口服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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