Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Windows Service not working

Windows Service not working

Scheduled Pinned Locked Moved Visual Basic
question
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    svanwass
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups