mcerk Posted January 3, 2006 Posted January 3, 2006 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 Quote
Administrators PlausiblyDamp Posted January 3, 2006 Administrators Posted January 3, 2006 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 Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.