Paul K <(E-Mail Removed)> wrote:
> Here's the code for the foreach statement:
>
> foreach (FileInfo fi in di.GetFiles("*.PSM"))
> {
> sr=fi.OpenText();
> do
> {
> currentline=sr.ReadLine()
>
> if (currentline!=null)
> {
> if (currentline.IndexOf(0,dbname) != -1)
> {
> found=true;
> mlgname=fi.Name
> }
> }
> }
> while (!found || currentline!=null);
> }
One thing you should try is calling Close or Dispose on each
StreamReader when you're finished with it. The easiest way to do this
is with the using construct:
foreach (FileInfo fi in di.GetFiles("*.PSM"))
{
using (StreamReader sr = fi.OpenText())
{
do
{
currentline=sr.ReadLine()
if (currentline!=null)
{
if (currentline.IndexOf(0,dbname) != -1)
{
found=true;
mlgname=fi.Name
}
}
}
while (!found || currentline!=null);
}
}
Otherwise you've got all the files open at the same time until garbage
collection kicks in.
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too