我正在逐行读取文本文件。从文本文件中读取线路跳过读取行
StreamReader reader = new StreamReader(OpenFileDialog.OpenFile());
// Now I am passing this stream to backgroundworker
backgroundWorker1.DoWork += ((senderr,ee)=>
{
while ((reader.ReadLine()) != null)
{
string proxy = reader.ReadLine().Split(':').GetValue(0).ToString();
// here I am performing lengthy algo on each proxy (Takes 10 sec,s)
}
});
backgroundWorker1.RunWorkerAsync();
现在问题是某些行不被读取。它在读取一行后跳过每一行。
我已阅读使用
File.ReadAllLines(file.FileName).Length
它让行的准确数量的行的总数。
我怀疑我的代码中存在BackgroundWorker机制的问题,但无法弄清楚。
我更新的问题 –
是否有可能在同时子句声明串! –
@ Zain:我认为你是对的,你不能。自从我大部分时间使用foreach循环以来,习惯的力量。我使用Jon Skeet的LineReader类,所以它通常看起来像这样:foreach(var line in new LineReader(fileName)){}; –