在一个控制台应用程序包一个C#服务进行调试 [英] Wrapping a C# service in a console app to debug it
问题描述
我想调试写在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?
感谢您
接口
推荐答案
这种方法我一直采取的是隔离的所有应用程序的逻辑到类库。这使得你的服务项目其实只是承载您的类库作为服务壳。
The approach I always take is to isolate out all of your application's logic into class libraries. This makes your service project really just a shell that hosts your class libraries as a service.
通过这样做,你可以很容易地进行单元测试和调试代码,而不必处理通过附加到进程的调试服务的头痛。我建议,当然单元测试,但如果你不这样做,然后添加调用同一个入口点为您服务是要走的路的控制台应用程序。
By doing this, you can easily unit test and debug your code, without having to deal with the headache of debugging a service by attaching to a process. I'd recommend unit testing of course, but if you're not doing that then adding a console application that calls the same entry point as your service is the way to go.
这篇关于在一个控制台应用程序包一个C#服务进行调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!