我有一个读取100个文本文件的项目,其中包含5000个单词。在c#中并行读取和处理100个文本文件
我将单词插入到列表中。我有第二个包含英语停用词的列表。我比较两个列表并删除第一个列表中的停用词。
需要1个小时,运行应用程序。我想将它并行化。我怎样才能做到这一点?
继承人我的代码:
private void button1_Click(object sender, EventArgs e)
{
List<string> listt1 = new List<string>();
string line;
for (int ii = 1; ii <= 49; ii++)
{
string d = ii.ToString();
using (StreamReader reader = new StreamReader(@"D" + d.ToString() + ".txt"))
while ((line = reader.ReadLine()) != null)
{
string[] words = line.Split(' ');
for (int i = 0; i < words.Length; i++)
{
listt1.Add(words[i].ToString());
}
}
listt1 = listt1.ConvertAll(d1 => d1.ToLower());
StreamReader reader2 = new StreamReader("stopword.txt");
List<string> listt2 = new List<string>();
string line2;
while ((line2 = reader2.ReadLine()) != null)
{
string[] words2 = line2.Split('\n');
for (int i = 0; i < words2.Length; i++)
{
listt2.Add(words2[i]);
}
listt2 = listt2.ConvertAll(d1 => d1.ToLower());
}
for (int i = 0; i < listt1.Count(); i++)
{
for (int j = 0; j < listt2.Count(); j++)
{
listt1.RemoveAll(d1 => d1.Equals(listt2[j]));
}
}
listt1=listt1.Distinct().ToList();
textBox1.Text = listt1.Count().ToString();
}
}
}
}
如果需要很长时间才能运行,则会出现问题。 – jdweng
我做了两个文件,列表数目是1780现在我做了49个文件和它的35分钟运行 – user3903589
两个文件运行需要多长时间? – jdweng