I have had some success making a windows service but I can’t seem to fix a simple issue
I can get the service to run through my code once, but I can’t get it to loop, well I can but then the service will not start correctly and just times out while the code is running.
How can I get the service to start and then loop, at the moment it just says starting service and the code is looping but the service wont start! Windows times it out after a few mins.
Thanks for any help u can offer me.
I can get the service to run through my code once, but I can’t get it to loop, well I can but then the service will not start correctly and just times out while the code is running.
How can I get the service to start and then loop, at the moment it just says starting service and the code is looping but the service wont start! Windows times it out after a few mins.
Thanks for any help u can offer me.
VB.NET:
Public Class WwService
Dim sDate As Date
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
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
Timer1.Interval = 10000 '10 secs
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
Timer1.Enabled = False
End Sub
Sub WRun()
sDate = DateValue(Now)
con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\WwService.mdb"
con.Open()
sql = "SELECT * FROM Table1"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "WwServ")
con.Close()
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("WwServ").NewRow()
dsNewRow.Item("Test_Date") = sDate
ds.Tables("WwServ").Rows.Add(dsNewRow)
da.Update(ds, "WwServ")
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
WRun()
End Sub
End Class