调试窗口服务 [英] Debugging windows services

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

问题描述

我创建了一个窗口服务,并手动安装它。后来开始从服务工具的​​服务。现在我想dubug从Visual Studio IDE中的Windows服务应用程序。 当我尝试从附加调试选项卡的过程中在IDE中,Windows服务程序显示在列表中,但没有突出显示要附加。 有没有办法,我要附加到调试服务应用程序的任何其他的主要过程。 发布任何相关信息AP preciated。

I have created a windows service and installed it manually. Later started the service from Services tool. Now I want to dubug the windows service application from Visual studio IDE. When I try to attach the process from Debug tab in the IDE, the windows service process is shown in the list, but it is not highlighted to be attached. Is there any other main process that I should attach to debug service application. Any relevant information posted is appreciated.

感谢。

推荐答案

这不回答确切的问题,但对于它的价值,我已经找到了发展的最简单的方法和调试Windows服务是把所有的逻辑到类库,然后调用逻辑,无论是从窗口服务(生产),或从一个普通窗口的形式(在开发过程中)。 Windows窗体将有一个开始和停止按钮,将模拟的启动和停止服务的行为。

This doesn't answer the exact question, but for what it's worth, I have found the easiest way to develop and debug a windows service is to put all of the logic into a class library and then call the logic from either a windows service (in production) or from a regular windows form (during development). The windows form would have a Start and Stop button which would simulate the start and stop behavior of the service.

要可以很容易地在两种模式之间切换,我只是用一个命令行参数和处理,在这样的Main方法:

To make it easy to switch between the two modes, I just use a command line parameter and handle that in the Main method like this:

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    private static void Main(string[] args)
    {
        if (args.Length > 0 && args[0] == "/form")
        {
            var form = new MainForm();
            Application.Run(form);
            return;
        }

        var servicesToRun = new ServiceBase[]
        {
            new BackgroundService()
        };

        ServiceBase.Run(servicesToRun);
    }
}

然后在Visual Studio项目属性的命令行参数字段中,你可以添加/表的参数,并在调试的时候在当地它总是弹出形式。这样,您就不必担心连接到一个过程或类似的东西。您只需点击调试像往常一样,你是好去。

Then in the "Command line arguments" field of the Visual Studio project properties, you can just add the "/form" parameter, and it will always pop up the form when debugging locally. This way you don't have to worry about attaching to a process or anything like that. You just click Debug as usual, and you're good to go.

这篇关于调试窗口服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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