I am currently writing an winforms c# application that will allow users to cleanse text / log files. At present the app is working, but if the file is massibe in size, i.e. 10MB it is taking an age!
The first cleanse it does is for users Windows Auth, i.e. who was logged in at the time. I have a textfile of all users in our organisation, roughly 10,000.
I load this into a
List<string> loggedUsers = new List<string>();
string[] userList = System.IO.File.ReadAllLines(@"C:\temp\logcleaner\users.txt");
foreach (string line in userList)
{
loggedUsers .Add(line.ToString());
}
Next i take a textfile and show it in a RichTextBox (rtbOrgFile), allowing the user to see see what information is currently there. The user then clicks a button which does the following:
foreach (var item in loggedUsers)
{
if (rtbOrgFile.Text.Contains(item.ToString()))
{
if(foundUsers.Items.Contains(item.ToString()))
{
// already in list
}
else
{
foundUsers.Items.Add(item.ToString());
}
}
}
My question is, is this the most efficient way? Or is there are far batter way to go about this. The code is working fine, but the as you start to get into big files it is incredibly slow.