473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

How to constantly check something without using a Timer

Hi everyone, I'm an old school vb6 user trying to transition to VB.NET.

Can anyone suggest a better approach to constantly checking something without using a timer?

I'm trying to constantly check a folder of text files to get the date modified of each file. I have no problems creating the filesystem object to extract the file info and dates. Currently using a timer I know is a poor approach to this but need some insight into a better way of constantly looping so the system resources aren't hogged.

Any help would be greatly appreciated.
Nov 18 '08 #1
9 1762
joedeene
583 512MB
I would use a timer? If you want to constantly refresh a directory's files and information for each file I'd use a timer but set its refresh rate/interval to like 1000 milliseconds. I know it would be better then using a Do While Loop statement, because it would freeze the program up.

joedeene
Nov 18 '08 #2
lotus18
866 512MB
Try FileSystemWatcher component : )


Rey Sean
Nov 18 '08 #3
balabaster
797 Expert 512MB
Try FileSystemWatcher component
Definitely the best approach.

There are some caveats to watch out for though - when you do a file rename or a save it'll cause a bunch of extraneous events to occur, so what you really have to do is wait for the event and then attempt to get a file lock on that file. Once the file lock occurs, the file has finished saving/writing and then you can go on to trigger what you need to.

If you go off the regular event, then you can run into concurrency issues.

The changed event can run many times on a file save. The created event however, is only raised once.
Nov 18 '08 #4
boyank
5
It's also worth noting that the FileSystemWatcher implementation does not work well for network directories (access through UNC paths or as mapped drive).
Nov 18 '08 #5
Everyone, Thank you very much. I truly appreciate your replies. Your recommendations worked out for me!
Nov 18 '08 #6
tlhintoq
3,525 Expert 2GB
It's also worth noting that the FileSystemWatcher implementation does not work well for network directories (access through UNC paths or as mapped drive).
I'm curious about this comment. You say it doesn't work well over a mapped drive or UNC path. I assume you have had bad experiences with this?

The reason I ask is because a couple of my programs use this extensively and I haven't seen any problems in the last year.

9 computers; each dumping 1800 jpg's per 8-hour day into directories on a server.

13 other computers reacting to those new files based on FileSystemWatcher, to either display or process the files in a given way.

I haven't seen an issue so far. What kind of issues have you run in to so I can try to head off problems?

Regards,
tlhIn'toQ
Nov 19 '08 #7
tlhintoq
3,525 Expert 2GB
Definitely the best approach.

There are some caveats to watch out for though - when you do a file rename or a save it'll cause a bunch of extraneous events to occur, so what you really have to do is wait for the event and then attempt to get a file lock on that file. Once the file lock occurs, the file has finished saving/writing and then you can go on to trigger what you need to.

If you go off the regular event, then you can run into concurrency issues.

The changed event can run many times on a file save. The created event however, is only raised once.

What do you think of this approach? Maybe you have a better scheme that what I do now.

I usually react to the event of a new file by adding it to a list of files to be processed. Then take it off the list after processing is successful. That way I can deal with a list of 2000 path strings, instead of 2000 triggered events.
Nov 19 '08 #8
balabaster
797 Expert 512MB
What do you think of this approach? Maybe you have a better scheme that what I do now.

I usually react to the event of a new file by adding it to a list of files to be processed. Then take it off the list after processing is successful. That way I can deal with a list of 2000 path strings, instead of 2000 triggered events.
Sounds good. I usually try and queue up the file into a dictionary so I don't get duplicates. I then check for an exclusive lock when I come to process the file to check that its finished processing.
Nov 19 '08 #9
tlhintoq
3,525 Expert 2GB
A dictionary... <light bulb>... I hadn't thought of that. Just never made the connection. I always just used a List<string> and did a manual search of the list before adding to avoid duplicates. I never put 1 and 1 together to get 10, that a dictionary inherently doesn't allow duplicates. Thanks!
Nov 23 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Steve Jorgensen | last post by:
I'm trying to figure out if there is a way to generate standard error handlers that "know" if the calling code has an error handler in effect (On Error Goto <label> or On Error Resume Next) before...
8
by: Nikola Bucic | last post by:
Could someone tell me how can I constantly check if I'm connected to internet and if possible to determine what type of connection is it. My best shot wright now is to have a timer which will...
2
by: Steven D'Aprano | last post by:
When using the timeit module, you pass the code you want to time as strings: import timeit t = timeit.Timer("foo(x, y)", \ """from module import foo x = 27 y = 45 """) elapsed_time =...
6
by: Bruno Alexandre | last post by:
How can we manage in ASP.NET (using a hosted website - so there is nothing I can do in the server) do perform a task every day at 11pm ? in VB.NET we have the timer and if the application is...
5
by: mabond | last post by:
Hi Can't believe I've not been able to find the answer to this in the on-line help. I have a CheckedListBox which, via a timer control, is populated with the names of files in a network...
4
by: John Salerno | last post by:
My code is below. The main focus would be on the OnStart method. I want to make sure that a positive integer is entered in the input box. At first I tried an if/else clause, then switched to...
0
by: lini | last post by:
Hello, I am writing some code in the scenario which can be described as follow: + program A which writes to standard output (e.g. cout >> whatever). + program B which has GUI and also listens to...
4
by: Andy B | last post by:
I need to make a program that stays in the xp/vista system tray. I have to constantly search xml files to make sure the program stays updated with the newest xml data. What is the least CPU...
18
by: navyjax2 | last post by:
What if your event handler has to be nonstatic?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.