调试 Windows 服务 [英] Debug Windows Service

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

问题描述

我有一个用 C# 编写的 Windows 服务.我已经阅读了关于如何调试它的所有谷歌线程,但我仍然无法让它工作.我已经运行了PathTo.NetFrameworkInstallUtil.exe C:MyService.exe".它说安装成功,但是当我运行Services.msc"时,该服务根本没有显示,任何地方.如果我进入任务管理器,会出现一个名为MyService.vshost.exe"的进程.很确定那不是它,因为它是一种服务,而不是一个过程.

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.NetFrameworkInstallUtil.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.

I'm running VS2008.

这一切都在我的本地机器上完成,我没有服务器或访问任何服务器.此外,我什至不知道该服务是做什么的,我想对其进行调试,以便我可以遍历代码并查看它是如何工作的(服务内部的代码,而不是服务本身 - 对于你们中的任何一个可能建议我看看模板).

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.

I'm running VS2008.

我输入了这个:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727InstallUtil.exe C:devRestarterinReleaseRestarter.exe

I typed this: C:WINDOWSMicrosoft.NETFrameworkv2.0.50727InstallUtil.exe C:devRestarterinReleaseRestarter.exe

我得到了这个:Microsoft (R) .NET Framework 安装实用程序版本 2.0.50727.3053版权所有 (c) 微软公司.保留所有权利.

I got this: Microsoft (R) .NET Framework Installation utility Version 2.0.50727.3053 Copyright (c) Microsoft Corporation. All rights reserved.

运行事务安装.

开始安装的安装阶段.查看 C:devRestarterin 的日志文件的内容ReleaseRestarter.exe 程序集的进度.该文件位于 C:devRestarterinReleaseEDT.Restarter.InstallLog.安装程序集C:devRestarterinReleaseRestarter.exe".受影响的参数有:登录控制台 =assemblypath = C:devRestarterinReleaseRestarter.exe日志文件 = C:devRestarterinReleaseRestarter.InstallLog

Beginning the Install phase of the installation. See the contents of the log file for the C:devRestarterin ReleaseRestarter.exe assembly's progress. The file is located at C:devRestarterinReleaseEDT.Restar ter.InstallLog. Installing assembly 'C:devRestarterinReleaseRestarter.exe'. Affected parameters are: logtoconsole = assemblypath = C:devRestarterinReleaseRestarter.exe logfile = C:devRestarterinReleaseRestarter.InstallLog

安装阶段成功完成,提交阶段开始.查看 C:devRestarterin 的日志文件的内容ReleaseRestarter.exe 程序集的进度.该文件位于 C:devRestarterinReleaseRestarter.InstallLog.提交程序集C:devRestarterinReleaseRestarter.exe".受影响的参数有:登录控制台 =assemblypath = C:devRestarterinReleaseRestarter.exe日志文件 = C:devRestarterinReleaseRestarter.InstallLog

The Install phase completed successfully, and the Commit phase is beginning. See the contents of the log file for the C:devRestarterin ReleaseRestarter.exe assembly's progress. The file is located at C:devRestarterinReleaseRestar ter.InstallLog. Committing assembly 'C:devRestarterinReleaseRestarter.exe'. Affected parameters are: logtoconsole = assemblypath = C:devRestarterinReleaseRestarter.exe logfile = C:devRestarterinReleaseRestarter.InstallLog

提交阶段成功完成.

事务安装已完成.

C:Program FilesMicrosoft Visual Studio 9.0VC>

C:Program FilesMicrosoft Visual Studio 9.0VC>

然后我去运行 -> 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".

就是这样.

我只想安装和调试它.我知道它有效(因为它运行并且不会崩溃).但是代码是朋友写的,我想通过调试模式来了解底层代码.

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屋!

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