如何运行VB.NET中内置的Windows服务 [英] How to run windows service built in VB.NET

查看:92
本文介绍了如何运行VB.NET中内置的Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

问候.

最近几周来,我遇到了麻烦.我已经在Microsoft Visual Studio 2010中使用VB.NET创建/编码了Windows服务,我想对其进行调试.

我搜索了许多解决方案,但无法使用已开发的服务.我还尝试安装该服务,然后将进程调试器附加到我的mprogram.完成后,我尝试添加调试桥,但不值得.

我想分享以下更多详细信息:

这是服务的VB代码

Dear Friends,

Greetings.

I am facing a trouble from last couple of weeks. I have created/coded a windows service using VB.NET in Microsoft visual studio 2010 which I am wanting to debug.

I searched many many solutions but could not get anything working with the service I have developed. I also tried to install the service and then attaching the process debugger to my mprogram. Once I am done I tried to add debug ponits, but not worth.

I would like to share more details as follows:

Here s the VB code for service

Public Class pspldemows

    Private bln_LogFlag As Boolean

    Protected Overrides Sub OnStart(ByVal args() As String)

        tmr_mainws.Interval = 1000
        tmr_mainws.Enabled = True

    End Sub

    Protected Overrides Sub OnStop()

    End Sub

    Private Sub tmr_mainws_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmr_mainws.Tick

        tmr_mainws.Enabled = False
        Me.WriteNewLog()
        tmr_mainws.Enabled = True

    End Sub

    Private Sub WriteNewLog()

        Try
            If True = bln_LogFlag Then

                Me.evntlog_mainlog.WriteEntry("pspldemows is alive")
                bln_LogFlag = False

            ElseIf False = bln_LogFlag Then

                Me.evntlog_mainlog.WriteEntry("pspldemows is now willing to die")
                bln_LogFlag = True

            End If

        Catch ex As Exception
            Me.evntlog_mainlog.WriteEntry("pspldemows|WriteNewLog():<ERROR>: " & ex.Message)
        End Try

    End Sub

End Class



通常需要将项目安装程序添加到其中,并添加serviceInstaller和serviceProcessInstaller的所有属性.

要安装项目,我为此创建了一个安装程序(按照下面的参考链接创建安装程序的指导),安装了程序.

http://myhosting.com/blog/2010/09/creating-windows -service-visual-studio-2010/ [



As generally required the project installer is also added to it and all the properties of serviceInstaller and serviceProcessInstaller.

To install the project I created a setup for this (as guided by following reference link to create setup), installed the program.

http://myhosting.com/blog/2010/09/creating-windows-service-visual-studio-2010/[^

When I have seen the services screen, I am able to see the service running, but not able to debug it.I am not getting where I am going wrong.

Guys, please help me out for this.

Your valuable suggestions and replies are appreciated in advance.

Thank you very much.

Regards,
G Nachiket

推荐答案

确保服务路径与解决方案路径相同(已从解决方案的bin \ debug文件夹中安装了服务). >
通过Visual Studio将调试器附加到您的服务.

如果需要调试服务初始化程序的启动,请在服务启动代码中添加Thread.Sleep(10000),以便您有时间附加调试器.
Make sure the service path is the same as your solution path (you installed the service from your bin\debug folder of your solution).

Attach the debugger to your service via Visual Studio.

If you need to debug the start of the service initializer, add a Thread.Sleep(10000) to your service start code so you have time to attach a debugger.


这篇关于如何运行VB.NET中内置的Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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