I have a problem with a service I created

G

Guest

Hi,
I created a service to execute every 2 hours but it only executes once at
startup. This is part of the code



Protected Sub Test(ByVal obj As Object)

Dim sDate As String = Date.Today.ToShortDateString

If sDate = "4/25/2005" Then

sEvent = "Test after 10Sec"
oEventLog.WriteEntry(sEvent, EventLogEntryType.Error, 200)

Else

Exit Sub

End If

End Sub



At startup.............

Dim TimerDelegate As New Threading.TimerCallback(AddressOf Test)

Dim TimerItem As New System.Threading.Timer(TimerDelegate, 1, _
5000, 10000)

Any ideas?
 
G

Guest

Chris,
I think you're missing the leading "0" in the month string you are comparing
in your "if" statement.

Try changing your "if" statement to this:

If sDate = "04/25/2005" Then

HTH,
Jorge
 
G

Guest

Hi,
I did that but still it doesn't work. It works every 5 mins if I set to

Dim TimerItem As New System.Threading.Timer(TimerDelegate, 1, _
5000, 50000)

but not for an hour or above if set like


Dim TimerItem As New System.Threading.Timer(TimerDelegate, 1, _
5000, 3600000 )

Why?
 
G

Guest

I'm surprised that it works every 5 minutes since it looks like you
configured it fire every 50 seconds (50 sec * 1000 ms = 50,000 ms)

Dim TimerItem As New System.Threading.Timer(TimerDelegate, 1, 5000, 50000)

I have a suggestion, try debugging your service code, you can either
"Attach" to the process hosting your service or you can develop your service
in a separate class library and instantiate it from a console application. I
prefer to do the latter since I can then unit test the service code.

You can also post the rest of your code for review.

Jorge
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top