特定のディレクトリから多くのテキスト ファイルを検索し、次に textchanged イベントを検索して、すべてのファイル内のテキストを検索し、そのテキストを含む行のみを画面に表示しようとしています。
現在、動作していますが、遅すぎます。テキストを検索してリストボックスに表示する機能を投稿しています。少し速く動作させるための最も効率的な方法は何ですか。
listBox2.Items.Clear();
ArrayList lines = new ArrayList();
if (txtfile.Count > 0)
{
for (int i = 0; i < txtfile.Count; i++)
{
lines.AddRange((File.ReadAllLines(Path.Combine(path, txtfile[i].ToString()))));
}
for (int i = 0; i < lines.Count; i++)
{
if(lines[i].ToString().IndexOf(txt,StringComparison.InvariantCultureIgnoreCase)>=0)
{
listBox2.Items.Add(lines[i].ToString());
}
}
}