调试Windows服务 [英] Debug Windows Service
问题描述
我有C#编写的windows服务。
我读过所有关于如何调试它的谷歌线程,但我仍然不能得到它的工作。
我已经运行PathTo.NetFramework \\ InstallUtil.exe C:\\ MyService.exe。它说,安装成功了,但是当我运行SERVICES.MSC,该服务不会显示在所有,任何地方。如果我进入任务管理器中,有一个名为MyService.vshost.exe的过程。 pretty肯定这不是它,因为它是一个服务,而不是一个过程。
I've got a windows service written in C#. I've read all the google threads on how to debug it, but I still can't get it to work. I've run "PathTo.NetFramework\InstallUtil.exe C:\MyService.exe". It said the install was successful, however when I run "Services.msc", The service isn't displayed at all, anywhere. If I go into Task Manager, there is a process called "MyService.vshost.exe". Pretty sure that's not it, because it's a service, not a process.
如果我应该看到服务,当我运行services.msc?
(记住,这是轴承都被本地计算机上完成,没有任何服务器都没有。
If I am supposed to see the service when I run Services.msc? (Bearing in mind this is all being done on a local machine, with no servers AT ALL.
我跑VS2008。
这是都被我的本地机器上完成,我没有服务器或访问任何。
另外,我甚至不知道服务做什么,我想调试它,所以我可以演示中,code,看到了服务,而不是里面它是如何工作(在code服务本身 - 这是任何你Smarty的裤子可能会建议我看一个模板)。
This is all being done on my local machine, I have no servers or access to any. Also, I don't even know what the service does, I want to debug it so I can walkthrough the code and see how it all works (the code inside the service, not the service itself - for any of you smarty pants that might suggest I look at a template).
这些正在无!
每当我的东西我得到不必使用NET START或安装服务的一些消息。
NONE OF THESE ARE WORKING! Everytime I try something I get some message about having to use NET START or install the service.
我跑VS2008。
我输入这样的:
C:\\ WINDOWS \\ Microsoft.NET \\框架\\ V2.0.50727 \\ InstallUtil.exe C:\\ dev的\\ Restarter的\\ BIN \\发布\\ Restarter.exe
I typed this: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe C:\dev\Restarter\bin\Release\Restarter.exe
我得到这个:
微软(R).NET Framework安装程序版本2.0.50727.3053
版权所有(c)Microsoft公司。保留所有权利。
I got this: Microsoft (R) .NET Framework Installation utility Version 2.0.50727.3053 Copyright (c) Microsoft Corporation. All rights reserved.
运行事务处理安装。
在开始安装的安装阶段。
请参阅C中的日志文件的内容:\\ dev的\\ Restarter的\\ BIN \\
发布\\ Restarter.exe集的进度。
该文件位于C:\\ dev的\\ Restarter的\\ BIN \\发布\\ EDT.Restar
ter.InstallLog。
安装程序集C:\\ dev的\\ Restarter的\\ BIN \\发布\\ Restarter.exe。
受影响的参数是:
logtoconsole =
assemblypath = C:\\ dev的\\ Restarter的\\ BIN \\发布\\ Restarter.exe
日志文件= C:\\ dev的\\ Restarter的\\ BIN \\发布\\ Restarter.InstallLog
Beginning the Install phase of the installation. See the contents of the log file for the C:\dev\Restarter\bin\ Release\Restarter.exe assembly's progress. The file is located at C:\dev\Restarter\bin\Release\EDT.Restar ter.InstallLog. Installing assembly 'C:\dev\Restarter\bin\Release\Restarter.exe'. Affected parameters are: logtoconsole = assemblypath = C:\dev\Restarter\bin\Release\Restarter.exe logfile = C:\dev\Restarter\bin\Release\Restarter.InstallLog
安装阶段顺利完成,并提交阶段正在开始。
请参阅C中的日志文件的内容:\\ dev的\\ Restarter的\\ BIN \\
发布\\ Restarter.exe集的进度。
该文件位于C:\\ dev的\\ Restarter的\\ BIN \\发布\\ RESTAR
ter.InstallLog。
提交程序集C:\\ dev的\\ Restarter的\\ BIN \\发布\\ Restarter.exe。
受影响的参数是:
logtoconsole =
assemblypath = C:\\ dev的\\ Restarter的\\ BIN \\发布\\ Restarter.exe
日志文件= C:\\ dev的\\ Restarter的\\ BIN \\发布\\ Restarter.InstallLog
The Install phase completed successfully, and the Commit phase is beginning. See the contents of the log file for the C:\dev\Restarter\bin\ Release\Restarter.exe assembly's progress. The file is located at C:\dev\Restarter\bin\Release\Restar ter.InstallLog. Committing assembly 'C:\dev\Restarter\bin\Release\Restarter.exe'. Affected parameters are: logtoconsole = assemblypath = C:\dev\Restarter\bin\Release\Restarter.exe logfile = C:\dev\Restarter\bin\Release\Restarter.InstallLog
提交阶段已成功完成。
成交安装已完成。
C:\\ Program Files文件\\微软的Visual Studio 9.0 \\ VC>
C:\Program Files\Microsoft Visual Studio 9.0\VC>
然后我去运行 - > SERVICES.MSC
我能看到什么在那里。
I then went to RUN -> Services.msc I can see nothing in there.
有是在任务管理器的过程称为Restarter.vshost.exe。
There is a process in Task Manager called "Restarter.vshost.exe".
这就是它。
我只是想安装和调试。
我知道它(因为它运行并不会崩溃)。
但是,code被写了一个朋友,我想通过它在调试模式走了解底层code。
I only wanted to install and debug it. I know it works (as it it runs and doesn't crash). But the code was written by a friend and I want to understand the underlying code by walking through it in debug mode.
推荐答案
我建议以下调试模式:
var ServiceToRun = new SomeService();
if (Environment.UserInteractive)
{
// This used to run the service as a console (development phase only)
ServiceToRun.Start();
Console.WriteLine("Press Enter to terminate ...");
Console.ReadLine();
ServiceToRun.DoStop();
}
else
{
ServiceBase.Run(ServiceToRun);
}
编辑:确保你的目标是控制台应用程序,而不是Windows应用程序,否则将无法正常工作
make sure that your target is Console Application, not Windows Application, otherwise it will not work.
这篇关于调试Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!