Windows Service not working
-
Rather simple windows service that has a timer set to 1 minute from NOW and when that time is reached, writes an event log entry. That was the idea, but nothing happens. Anybody know what i am doing wrong?
Public Class Service1 Private alarmTime As Date 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. 'Dim a As TimeSpan = Date.Now.Subtract(Date.Today.AddDays(1)) 'Dim tomorrow As Date = New Date 'tomorrow = Date.Now.AddDays(1) 'Me.alarmTime = New Date(tomorrow.Year, tomorrow.Month, tomorrow.Day, 0, 1, 1, 1) Me.alarmTime = Date.Now.AddMinutes(1) Me.Timer1.Start() End Sub Protected Overrides Sub OnStop() ' Add code here to perform any tear-down necessary to stop your service. End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) If alarmTime < Date.Now Then Me.Timer1.Stop() Dim MyLog As New EventLog() ' create a new event log ' Check if the the Event Log Exists If Not Diagnostics.EventLog.SourceExists("SQLBackup") Then Diagnostics.EventLog.CreateEventSource("SQLBackup", "SQLBackup") ' Create Log End If MyLog.Source = "SQLBackup" ' Write to the Log Diagnostics.EventLog.WriteEntry("SQLBackup", "Event fired at " & CStr(TimeOfDay), EventLogEntryType.Information) Else Dim remainingTime As TimeSpan = Me.alarmTime.Subtract(Date.Now) 'Me.Label1.Text = String.Format("{0}:{1:d2}:{2:d2}", _ 'remainingTime.Hours, _ 'remainingTime.Minutes, _ 'remainingTime.Seconds) End If End Sub End Class