Timer in windows service (VS 2005)

mcerk

Regular
Joined
Nov 1, 2004
Messages
78
Hi, I want to create a windows service with a timer. So one event will fire on every while. I'm using Visual Studio 05

But it doesn't work. The code is fine, becouse it works in normal win app.

with sql.Insert_Log I just inser a log into db, so I can see that service is working. All I get in my log file is 'Start Service' and 'Stop service'.

The timer tick event never starts.

what is wrong?

Visual Basic:
   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.

        'set connstring 
        sql.ConnectionString = sConn
        pp.sql = sql

        sql.Insert_Log(clsSQLfunctions.ErrorTypes.Importance1, 1, "Start Service", "") 

        'zagon timerja
        Timer1.Interval = 10 '* 3600
        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
        sql.Insert_Log(clsSQLfunctions.ErrorTypes.Importance1, 1, "Stop Service", "")
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        sql.Insert_Log(clsSQLfunctions.ErrorTypes.Importance1, 1, "Timer Tick", "")
        'pp.PreparePictures()
    End Sub
 
Try using a System.Threading.timer instead
Visual Basic:
    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 t As New System.Threading.Timer(AddressOf TestCallback, Nothing, 0, 1000)


    End Sub
    Private Sub TestCallback(ByVal state As Object)

    End Sub
 
Back
Top