• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

C# 服务包装在控制台应用程序以对其进行调试

用户头像
it1352
帮助1

问题说明

我想调试一个用 C# 编写的服务,而老式的方法太长了.我必须停止服务,启动在调试模式下使用该服务的应用程序(Visual Studio 2008),启动该服务,附加到服务进程,然后在我的 Asp.Net 应用程序中导航以触发该服务.

I want to debug a service written in C# and the old fashioned way is just too long. I have to stop the service, start my application that uses the service in debug mode (Visual studio 2008), start the service, attach to the service process and then navigate in my Asp.Net application to trigger the service.

我基本上是在后台运行服务,等待任务.Web 应用程序将触发要由服务获取的任务.

I basically have the service running in the background, waiting for a task. The web application will trigger a task to be picked up by the service.

我想做的是有一个控制台应用程序来触发服务以便我进行调试.有没有人知道的简单演示?

What I would like to do is to have a console application that fires the service in an effort for me to debug. Is there any simple demo that anybody knows about?

正确答案

#1

你可以在主入口点做这样的事情:

You can do something like this in the main entry point:

static void Main()
{
#if DEBUG
    Service1 s = new Service1();
    s.Init(); // Init() is pretty much any code you would have in OnStart().
#else
    ServiceBase[] ServicesToRun;
    ServicesToRun=new ServiceBase[] 
    { 
        new Service1() 
    };
    ServiceBase.Run(ServicesToRun);
#endif
}

并在您的 OnStart 事件处理程序中:

and in your OnStart Event handler:

protected override void OnStart(string[] args)
{
    Init();
}

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfjjeh
系列文章
更多 icon
同类精品
更多 icon
继续加载