473,809 Members | 2,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to constantly check something without using a Timer

9 New Member
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 1787
joedeene
583 Contributor
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 Contributor
Try FileSystemWatch er component : )


Rey Sean
Nov 18 '08 #3
balabaster
797 Recognized Expert Contributor
Try FileSystemWatch er 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 New Member
It's also worth noting that the FileSystemWatch er implementation does not work well for network directories (access through UNC paths or as mapped drive).
Nov 18 '08 #5
TomLasky
9 New Member
Everyone, Thank you very much. I truly appreciate your replies. Your recommendations worked out for me!
Nov 18 '08 #6
tlhintoq
3,525 Recognized Expert Specialist
It's also worth noting that the FileSystemWatch er 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 FileSystemWatch er, 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 Recognized Expert Specialist
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 Recognized Expert Contributor
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 Recognized Expert Specialist
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
2657
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 deciding how to respond. Does anyone know if this is possible.
8
11684
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 periodicaly call API to check whether am I connected or not
2
2703
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 = t.timeit()
6
1697
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 running we can every 5 minutes see if the clock is right then execute the function, but how about in ASP.NET, since we deveop for the same framework, shouldn't we had the same thing? I need to send the daily sales reports to email of the work list...
5
6871
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 folder. The "check mark" for each item in the control is determined by the boolean value of a custom property field of the file. That value is found using microsoft's dsofile.dll class.
4
3692
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 try/except. Neither is perfect yet, but I was wondering which I should try for in the first place. I figure I need to check for an emptry string, non-numeric strings (maybe these are the same check), 0 and negative numbers (which might also fall into...
0
1852
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 the standart input regularly (using a timer) if there is no input, it returns to the GUI and does something else. What I expect is B should work without problem in both cases: (1) user@host $ A | B (2) user@host $ B In B's code, I tried...
4
1406
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 intensive way to do this? Would it be Timer or BackgroundWatcher?
18
3949
by: navyjax2 | last post by:
What if your event handler has to be nonstatic?
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10637
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7660
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.