try
{
foreach (string filename in filenames)
{
Globals.dtStart = DateTime.Now;
if (Globals.strFilename.IndexOf("$FILE") >= 0)
{
workpath = Path.GetDirectoryName(filename);
sFilename = workpath + "\\" + "S4S-" + Globals.strFilename.Replace("$FILE", Path.GetFileName(filename));
}
else if (Globals.strFilename != "")
{
workpath = Path.GetDirectoryName(filename);
sFilename = workpath + "\\" + Globals.strFilename;
}
else if (Globals.strFilename == "")
sFilename = Application.StartupPath + @"\" + "Search4String.txt";
lFiles++;
bgWorker5.ReportProgress(3, lFiles.ToString());
workpath = Path.GetDirectoryName(filename);
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using (StreamReader sr = new StreamReader(fs))
{
string file = Path.GetFileName(filename);
//bgWorker.ReportProgress(1, "Processing file: " + file);
bgWorker5.ReportProgress(1, file);
while ((sData = sr.ReadLine()) != null)
{
lLines++;
if (lCollection == aCollection.Length - 25)
{
Array.Resize(ref aCollection, aCollection.Length + 500);
}
if (Globals.aKEYS.Length > 1)
{
for (int i = 0; i < Globals.aKEYS.Length; i++)
{
if (sData.IndexOf(Globals.aKEYS[i]) > 0)
{
GetCollection(sData, sArray, file, bgWorker5, e);
break;
}
}
}
else
{
GetCollection(sData, sArray, file, bgWorker5, e);
//break;
}
}//while ((sData = sr.ReadLine()) != null)
sr.Close();
PrintCollection(aCollection, lCollection, sFilename);
dtStop5 = DateTime.Now;
TimeSpan span = dtStop5.Subtract(Globals.dtStart);
sDuration = span.Hours.ToString("00") + ":" + span.Minutes.ToString("00") + ":" + span.Seconds.ToString("00") + "." + span.Milliseconds.ToString("000");
string[] result = new string[4];
result[0] = file;
result[1] = lLines.ToString("#,##0");
result[2] = iMatch.ToString("#,##0");
result[3] = sDuration;
lTotalLines += iMatch;
bgWorker5.ReportProgress(0, result);
bgWorker5.ReportProgress(2, lTotalLines.ToString());
lLines = 0;
iMatch = 0;
}//using (StreamReader sr = new StreamReader(filename))
}//foreach (string filename in filenames)
lFiles = 0;
}//try
the last iteration in the try loop is the one that fails the other (for example 3 files) two tries are ok. always the last update fails. I'm not sure why. stepping through (debug mode) shows it going to the process but the GRIDVIEW only has two files.