Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timer for Checking update on file every 10 minutes 5

Status
Not open for further replies.

badrion

Programmer
Jul 16, 2001
34
US
I know how to create a timer but I need the lastmodifieddate TIME only to check every 10 minutes on a file. I will be comparing it to the system time. Any ideas???
 
dim sTime as string
sTime = 'Timestamp it here

'this will check the difference in minutes etween the time that you stamped your variable, and the current time
if DateDiff("n", sTime, Now) > 10 Then

end if
 
If I understand you correctly you want a timer with a interval of above a minute? Well if you get mb hi res timer (free at it can be set that high I think.

In that timer you would have to code it of course. I could help on that do but I don't have vb at the moment.
 
if the file (the file being uploaded to an AS400) is inactive for 10 minutes i need it to throw up a flag
 
If the question is simply how to get a 10 minute timer, then set the Timer's interval to 60000, and then add this code to the Timer event:

Private Sub Timer1_Timer()
Static Minutes As Long

Me.Enabled = False
Minutes = (Minutes + 1) Mod 10
If Minutes = 0 Then
' Whatever you want to do
End If
Me.Enabled = True
End Sub
 
You can't do this with a timer which fires every 10 minutes. Potentially the file could be unchanged for nearly 20 minutes before you would notice it.

Consider this example.

1 second after your timer triggers, the file changes. The next time the timer triggers, it notices that file has changed and thinks all is OK. 10 minutes later, the timer is triggered again and at that point the event is raised, 19 mins and 59 seconds after the file last changed.

It comes down to timer granularity. If you need 2 second granualarity then you need to fire the timer every second.

What I would do is fire the trigger as often as possible and check the file, noting its last modified time. If the difference in time is > 10 mins, fire an event.

The frequency is up to you, but you may need to consider network traffic if the file is on a share.

Also, before you note the time, try to open the file in exclusive mode. If the file is currently being written you probably want to wait until the write is complete before checking any file modified times.

Chaz
 
Chaz,

one small disagreement with "... What I would do is fire the trigger as often as possible and check the file, noting its last modified time. If the difference in time is > 10 mins, fire an event. ..."

I would urge some caution in making this statement. "badrion" is obviously not conversant w/ the timer function - or it's potential consequences. Setting a time to the lowest possible value will certainly slow HIS system to doing nothing else, and generate enough network traffic to get a visit from the net police.

Personally, I would suggest setting the timer for the exact interval - and then adjust the interval such that the next interval would be just a few seconds past the (ten minute interval) from the file data-time stamp. This is a bit more code - but relieves the local machine and the network of un-necessary traffic.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Not quite a fair comment actually. The 1 millisecond - at best - resolution of the Timer control on even two or three year old machines (by which I'm effectively processor talking about clock speed) actually has a fairly imperceptible impact on overall performance (for a variety of reasons, amongst which are the facts that VB is by default single-threading and that all the timer does is post a message to the thread's message queue). Naturally, if you try and run a huge bunch of code on each millisecond event there will be an impact, but if all you do is run a quick check to see whether you ought to be doing something, and that something is only likely to be rquired every 5 to 10 minutes then it really doesn't have a major impact on system performance.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top