Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

 


  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

  • Administrators
Posted

Try using a System.Threading.timer instead

   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

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...