Start / Timer Issue

sakkara

New member
Joined
Sep 8, 2008
Messages
1
Programming Experience
3-5
Hi,
I am coding on VB.net 2.0, trying to work with a windows service. The code is below:-

VB.NET:
Imports System.ServiceProcess

Public Class Main
    Public Shared Sub Main()

    End Sub

    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.
        Timer1.Enabled = True
    End Sub

    Protected Overrides Sub OnStop()
        ' Add code here to perform any tear-down necessary to stop your service.
        Timer1.Enabled = False
    End Sub

    Private Sub Timer1_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        Dim Writer As New IO.StreamWriter(path:="C:\test.txt", Append:=True)
        Writer.WriteLine("hi")
        Writer.Close()
    End Sub
End Class

When I run from inside VS, the timer never actually fires. Same occurs when I install and try to run as a service (from control panel). I can confirm that my timer is System.Timers.Timer (and not the form based timer).

Can someone please give me an idea what is going on, and how to resolve it?

Much appreciated!
 
Hello.

A similar Problem was discussed here: http://www.vbdotnetforums.com/windows-services/27333-problem-timer.html

But as I see you're already using Timers.Timer instead of Forms.Timer. I'd suggest that you try to write Log Entries or Debug.Print Entries (you can track them outside the IDE with the sysinternal Tool DbgView), to see if the timer is once ticking or never. Also to check the timer state at the start.

Bobby
 
Back
Top