我有一個讀取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