Jobs这个类负责windows service实际上要干的活
Public Class Jobs
Private m_log As EventLogPublic 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