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???
'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
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.
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.