Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This windows service would check every minute for pending records to be processed, once for the testing site, and once for the production site; I have only 1 subroutine with a parameter to indicate if testing site so the right SQL connection string is used.

I'm using the Elapsed event to call the subroutine 2 times but only the first one gets called or processed.

What I have tried:

Please see code below, it is only adding the event log entry and calling CheckPendingiMacros(False), then it goes out the event handler.

VB
Private Shared iMacrosExecuterTimer As Timers.Timer

    Protected Overrides Sub OnStart(ByVal args() As String)
        'Initiate and set timer
        iMacrosExecuterTimer = New Timers.Timer
        iMacrosExecuterTimer.Interval = 10000 '10 seconds so it start immediately after it gets enabled, then it will be called every minute
        AddHandler iMacrosExecuterTimer.Elapsed, AddressOf OnTimedEvent
        iMacrosExecuterTimer.AutoReset = False
        iMacrosExecuterTimer.Start()
    End Sub 'OnStart

    Protected Overrides Sub OnStop()
    End Sub 'OnStop

    Private Sub OnTimedEvent(source As Object, e As System.Timers.ElapsedEventArgs)
        iMacrosExecuterEventLog.WriteEntry("OnTimedEvent: S T A R T E D", EventLogEntryType.Information) 'added for testing purposes
        'Testing Site
        CheckPendingiMacros(True)

        'Production Site
        CheckPendingiMacros(False)
        iMacrosExecuterEventLog.WriteEntry("OnTimedEvent: E N D E D", EventLogEntryType.Information) 'added for testing purposes

        'Re-Start the service again
        iMacrosExecuterTimer.Interval = 60000
        iMacrosExecuterTimer.Start()
    End Sub

    Private Sub CheckPendingiMacros(ByVal TestingSite As Boolean)
        'Set log entry to identify if running for the TestingSite or Production site
        iMacrosExecuterEventLog.WriteEntry(IIf(TestingSite, "Check Pending iMacros on:" & vbCr & "*** TestingSite Site ***", "Check Pending iMacros on:" & vbCr & "--- Production Site ---"), EventLogEntryType.Information)
Posted
Updated 15-Jun-17 14:52pm
Comments
Alan N 15-Jun-17 14:42pm    
Is an exception thrown by CheckPendingiMacros(true)? The Microsoft code that calls the event handler delegate swallows exceptions and your own exception trapping WITHIN the event handler will reveal any problems.
dgonzale 15-Jun-17 14:47pm    
Well, it executes the process with any parameter (True or False), I'm using a Try Catch section with an eventlog entry created if an error occurs but no errors are being captured.
dgonzale 15-Jun-17 14:50pm    
I don't know how to debug a service, so I'll add some events entries indicating the end of each of the process, like you said it might be an error and I'm not seeing it.

1 solution

There was an error, I enclosed OnStart on a Try Catch and I was able to identify the problem. Thank you!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900