Form Timer Event

shudini

Registered User.
Local time
Today, 16:18
Joined
Mar 1, 2007
Messages
114
Hello all. I have a strange situation which I have not had much success in finding any solution for, so maybe someone here can help.

I have a database which, when started, loads up a form. The purpose of this form is to perform certain actions on a one minute loop basis (basically, it checks our web logs to see if subscribers have requested information on a specific item, and if so, it prepares and emails the reports to that subscriber). There is a timer event which handles the countdown, and when it hits 0, it runs the predefined events.

The computer that this is running on is running Windows XP Pro SP2. There are virtually no other programs (aside from basics like antivirus etc.) running besides Outlook which handles the sending of the emails.

For some reason, and this is not consistent, the form seems to slow down or stop - not freeze or hang, just stop, but if you move the mouse or click on the form, it continues.

Initially when this happened, I added a call to the form's SetFocus method and I thought that had fixed it. Unfortunately, the issue seems to have recurred.

I turned off the screen saver, set the hard drive to never go off... nothing seems to work.

Any ideas?

-Thanks
 
You need to post the pertinent code for us to look at. Also, what is the Timer Interval set to?
 
Thanks for taking interest. The timer interval is set to 1000. Here is the Timer Event:
Code:
Private Sub Form_Timer()

    anaActID = 11
    analystID = 11
    analystName = "Admin"
    sec = sec - 1
    If sec < 0 Then
        sec = 59
        min = min - 1
    End If
    If min < 0 Then min = 0
    txtTime.Value = Format(min, "00") & ":" & Format(sec, "00")
    If min = 0 And sec = 0 Then
        txtTime.Visible = False
        lblStatus.Caption = "Processing..."
        Me.Repaint
        processWebLog
        postWorksheets
        hideStatus
        lblStatus.Caption = "Next Log scan in:"
        txtTime.Visible = True
        Me.Recalc
        Me.SetFocus
        Me.Repaint
    End If

End Sub
 
And the code for:

processWebLog
postWorksheets


Could it be possible that it's not finishing what it is trying to do with those two procedures and then the timer is firing again and trying to start the same procedures again and therefore hanging?
 
As i mentioned, the form is not hanging, just idling - almost as if the computer is on yet in stand by mode. When i move the mouse on the computer or click on the form, everything continues with no hitches, so it's not a problem with the programming. It also only begins to happen after a while, not initially (we leave the computer running on its own since it is on a perpetual loop).

I have implemented a backup whereby admins using the system are alerted if it has not completed the loop within the past 20 minutes, so they can go and move the mouse to get it going again, but it seems to have something to do with the computer idling. Have you ever encountered something like this?

I can give you the code for those procedures if you want, but i don't think they will help you help me.

Thanks
 
Why are you firing the timer event every second. That seems excessive when you only need one every minute.
 
I know you said you turned off your screen saver, but does your particular system have a parameter that is set to invoke a standby or power saving mode?
 
I know it's excessive, but this way I see the countdown. It doesn't matter from a processing perspective since it's on a dedicated system.

As far as some kind of system parameter, I checked every setting I know of in Windows XP but every one I know of is turned off. This is why I'm hoping someone here might be able to help me out.

Thanks again for your interest.
 
Have you tried setting the TimerValue to 30000 to see if the problem goes away?
 
i guess i can try that. i'll keep you posted.

Any theories on why that would make a difference?
 
As Bob mentioned in post #4, the code could be taking longer that a second and is not re-entrant.
 
When the counter hits 0, the timer even calls the procedures mentioned. These procedures can take up to a few minutes to process. Because the procedure is called from the timer event, the timer event is not again fired until the other procedures return control to the timer event which is when they finish executing.

The proof of this is that given that there is no problem with the form as long as the computer is not idle - even when processing many reports, I can see what is happening, and what is happening is that the form displays Processing... as long as the other procedures are running. Once those procedures complete, the field displays "Next log scan in: " and restarts from 00:59.
 
Set your TimerValue to 0 to turn off the Timer Event before executing extended code. you can set it back to 1000 when you are all done. Access is single threaded and can only do one thing at a time.
 
Do you really think the Timer Event is firing even when it's in the middle of running the Timer Event?

Why would this not cause my program to crash any time the processing takes longer than 1 second?

This lead me to believe that the Timer Event fires 1 second after completing the previous Timer Event - do you think this is wrong?

The core of my question is why should changing the TimerValue fix a problem that doesn't exist unless the computer is idle?

In either case, I will do as you suggest and let you know what happens.

Thanks to all!
 
Do you really think the Timer Event is firing even when it's in the middle of running the Timer Event?

!


well it is possible and you don't need to fire it so often.
 
well it is possible and you don't need to fire it so often.
Today 11:41 AM

As i mentioned, it is purely for convenience, to see where the form is holding in its countdown, and since nothing was crashing, I didn't see why not. I don't think you're correct that the TimerEvent is firing while it's still running - if that was the case I would have a system crash often given that sometimes there's 10 minutes of processing reports before it resumes its 1 minute loop.

I really appreciate all of your help, I hope we're on the right track. So far, after applying RuralyGuy's advice, the form has not paused. This doesn't mean it's fixed, since sometimes I only find out in the morning that it didn't run overnight, but in either case, I definitely learned something valuable. I always assumed that the TimerInterval was started from the point that TimerEvent completed, but now I see this is not the case.

I will post next week an update if the form is still running.

Thanks so much for all of your interest and help!
 
Just an update...

After checking the logs, the form has been successfully looping without stopping over the entire weekend.

Thanks for all your help!
 

Users who are viewing this thread

Back
Top Bottom