How can I process listview items?

flynn

Regular
Joined
Jul 28, 2005
Messages
59
I have a listview that I populate with file names from a folder that is being watched (using FileSystemWatcher via "AddHandler FileWatch.Created, AddressOf FileWatchNewFile"). When a new file is created in the folder, it is added to the listview from the FileWatchNewFile function.

Processing each file could take up to a minute or two, so the listview could contain dozens of entries that are waiting to be processed. Once a file is processed, it is flagged/removed. It's possible that all the files could be processed so that the listview becomes empty.

My question is this: What is the best way to watch the listview in order to process the entries (filenames) as they show up?
Should I use a timer that would fire every 10 seconds to see if the file processing code is waiting to be called? What if the file processing code is still processing a file?

Hopefully you get the idea.

tia
flynn
 
I would have a global boolean blRunning that you set to true when the file processing code starts and false when it finishes. When each file is added to the listbox I would check if blRunning is false and if so call the file processing code. The file processing code, once finsihed with one file should then check if the listbox has any items still in it and if so process another one.

In this way the fileprocessing code will run until the listbox is empty and then start up again when another file is added.

:)
 
Back
Top