473,385 Members | 1,333 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,385 software developers and data experts.

Baffling problem with DirectoryInfo.GetFiles

Hello Group,

I'm bemused as to why this code isn't working. It's a
very simple loop over the array of FileInfo objects
returned from DirectoryInfo.GetFiles. It works fine until
the eigth iteration at which point it blows up, everytime.

Sample Code:
...
Imports System.IO
...
Dim fInfo, fsInfo() As FileInfo
Dim dirInfo = New DirectoryInfo ("c:\")
fsInfo = dirInfo.GetFiles
For Each fInfo in fsInfo
Console.WriteLine fInfo.Name
Next
...

It collapses saying 'The handle is invalid'. Looking at
things in the debugger only leads to more confusion since
I can see 14, apparently valid, FileInfo objects in fsInfo.

Changing to a different directory, in fact, changing anything
makes no difference. It's always the eigth time.

What the heck?

Dominic
Nov 21 '05 #1
1 1674
Dominic Marks wrote:
Hello Group,

<snip/>

Changing to a different directory, in fact, changing anything
makes no difference. It's always the eigth time.

What the heck?

Dominic


I seem to be making a habit of replying to my own questions,
anyway - I discovered it was, as usual, all my own fault :-)

When using a ThreadPool beware of the main thread exiting in
the background, I assumed my that since all the programs data
was in the thread, it wouldn't matter. For example my Main
consists of just:

Public Shared Sub Main()
ThreadPool.QueueUserWorkItem(AddressOf TraverseFileSystem, _
New String("C:\"))
Thread.Sleep(1000)
End Sub

But extending the Sleep to 100 seconds fixes the problem, so
it clearly matters. If anyone knows why it matters, I assume
its a fairly self-explainatory reason I'd be interested to
find out.

Thanks,
Dominic
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Juan Manuel Ramollino | last post by:
Greetings everyone! I am creating a webcontrol that reads one or more directorie's content and displays all the filenames (tipically PDFs or PPTs) so that the user can select the desired one and...
0
by: Glenn Venzke | last post by:
I have an aspx page that is set up to copy backed-up DB files from a shared directory to a local folder. For some reason, it is being denied access to the network share. I have the web app running...
4
by: Remco Ploeg | last post by:
Hi, I wan to fill a dropdownlist with the filenames in a certain directory, i use the following statement for retrieving the files: DirectoryInfo di = new...
3
by: xenophon | last post by:
This following innocuous code: System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo(); System.IO.FileInfo ppp = fff.GetFiles( Request.MapPath(".") ); for( int ccc=0 ; ccc < ppp.Length ;...
13
by: Tom Scales | last post by:
OK, I admit, I am not a VB.NET expert and am still learning, but have run into an annoying problem. I'm writing a program that has to search the file system and therefore processes large numbers...
2
by: pittster | last post by:
Hi, I've bound a Gridview control to the GetFiles method Here is a code snippet: DirectoryInfo objDi = new DirectoryInfo(Server.MapPath("./somepath")); FileInfo arrFileInfo =...
3
by: Daniel C. Di Vita | last post by:
I am stating to write a small app that allows a user to catalog their CD/dvd collection. I need some help, however. Here is some test code I wrote for the recursive listing: Imports System...
4
by: rn5a | last post by:
I have a ListBox which should list all the files & directories that exist in a particular directory. The problem is I can get the ListBox to list either all the files or all the directories but not...
1
by: jobs | last post by:
Say I only have a single file I want to get information on. How can I adapt this code? Dim dr As DataRow Dim fi As FileInfo Dim dir As New DirectoryInfo(filename) Dim dt As New DataTable...
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.