C# 服务包装在控制台应用程序以对其进行调试
问题说明
我想调试一个用 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?
正确答案
你可以在主入口点做这样的事情:
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
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20