windows service 简单示例

Jobs这个类负责windows service实际上要干的活


Public Class Jobs

    Private m_log As EventLog


    Public Sub Dosomething ()
        If m_log Is Nothing Then
            If Not EventLog .SourceExists ("MyService1") Then
                EventLog .CreateEventSource ("MyService1", "Application")
            End If


            m_log = New EventLog ("")
            m_log .Source = "MyService1"
        End If


        m_log .WriteEntry (Date .Now .ToString)
    End Sub

End Class


Service1这个类是windows service类的主体和接口

Imports System.Threading


Public Class Service1
    Private m_Timer As Timer
    Private m_myJob As Jobs
    Private m_TimerCallback As TimerCallback


    Protected Overrides Sub OnStart(ByVal args() As String)
        ' Add code here to start your service. This method should set things
        ' in motion so your service can do its work.
        m_myJob = New Jobs
        m_TimerCallback = New TimerCallback(AddressOf m_myJob.Dosomething)
        m_Timer = New Timer(m_TimerCallback, Nothing, 1000, 10000)


        
    End Sub


    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        m_Timer.Dispose()
    End Sub
End Class

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值