Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6148363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:16:04+00:00 2026-05-23T19:16:04+00:00

I am reading from a text file line by line. StreamReader reader = new

  • 0

I am reading from a text file line by line.

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();

Now problem is that some lines are not being read. It skips each line after one line read.

I have read the total number of lines using

File.ReadAllLines(file.FileName).Length

It gives accurate number of lines.

I suspect there is some problem with BackgroundWorker mechanism in my code, but can’t figure it out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:16:05+00:00Added an answer on May 23, 2026 at 7:16 pm

    In while ((reader.ReadLine()) != null) you are not assigning the result to anything, as such it (the line which gets read during that call) will get skipped.

    Try some variation of:

    string line = reader.ReadLine();
    while (line != null)
    {
      /* Lengthy algorithm */
      line = reader.ReadLine();
    }
    

    You might prefer:

    string line;
    while ((line = r.ReadLine()) != null) {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading lines from a text file using (line-seq (reader input.txt)) . This collection
When reading lines from a text file using python, the end-line character often needs
I'm having problems reading lines from a text file in PHP. I have this
I got reading from a text file line by line working - but I
Anyone got anything about reading a sequential number from text file per line and
I have a large text file I am reading from and I need to
I'm reading text from a flat file in c# and need to test whether
I'm having a problem where instead of reading a text file from the location
I need some help reading data from a text file into my ArrayList .
gcc 4.4.4 c89 I am reading in from a text file and the text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.