对于小目录大小的代码工作正常,当目录文件大小很大时它会给出此错误消息。
我的代码:
IEnumerable<string> textLines =
Directory.GetFiles(@"C:\Users\karansha\Desktop\watson_query\", "*.*")
.Select(filePath => File.ReadAllLines(filePath))
.SelectMany(line => line)
.Where(line => !line.Contains("appGUID: null"))
.ToList();
List<string> users = new List<string>();
textLines.ToList().ForEach(textLine =>
{
Regex regex = new Regex(@"User:\s*(?<username>[^\s]+)");
MatchCollection matches = regex.Matches(textLine);
foreach (Match match in matches)
{
var user = match.Groups["username"].Value;
if (!users.Contains(user))
users.Add(user);
}
});
int numberOfUsers = users.Count(name => name.Length <= 10);
Console.WriteLine("Unique_Users_Express=" + numberOfUsers);