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

  • SEARCH
  • Home
  • 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 9159715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:33:42+00:00 2026-06-17T13:33:42+00:00

I am looping through a dataset in c# read from an excel file that

  • 0

I am looping through a dataset in c# read from an excel file that contains X records. For testing purposes, I used Thread.Sleep() to pause the output for a second after each record is read. My understanding was that they way I wrote my loop, it should pause for 1 second then display 1 line of output (1 record), pause for 1 second, display 1 line, etc… However, when I execute the code I get a X second long pause followed by all records immediately being output to screen. Anyone know why this is happening? I inserted a breakpoint and stepped through it and everything seems to be working fine (no errors or anything). Sorry if this is a basic question but I’m a bit of green programmer.

private void ReadExcelFile()
    {
        string fileAndPath = fileTextBox.Text;
        string fileName = Path.GetFileName(fileAndPath);
        string directoryPath = Path.GetDirectoryName(fileAndPath);

        var connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileAndPath + ";Extended Properties=\"Excel 12.0;IMEX=1;HDR=NO;TypeGuessRows=0;ImportMixedTypes=Text\""; ;
        using (var conn = new OleDbConnection(connectionString))
        {
            conn.Open();

            var sheets = conn.GetOleDbSchemaTable(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
            using (var cmd = conn.CreateCommand())
            {
                cmd.CommandText = "SELECT * FROM [" + sheets.Rows[0]["TABLE_NAME"].ToString() + "] ";

                var adapter = new OleDbDataAdapter(cmd);
                var ds = new DataSet();
                adapter.Fill(ds);

                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    user = row.ItemArray[0].ToString();
                    email = row.ItemArray[1].ToString();
                    password = row.ItemArray[2].ToString();
                    Thread.Sleep(1000);                   

                    excelTextBox.Text += user + "     " + email + "     " + password + "     " + Environment.NewLine;
                }                    
            }
        }
    } 
  • 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-06-17T13:33:43+00:00Added an answer on June 17, 2026 at 1:33 pm

    Since you are running this method on the main thread (the UI’s thread), the thread isn’t available to process events (e.g. display updates).

    You can do something similar to this to process UI messages:
    https://stackoverflow.com/a/3121934/38368

    Or, better yet, redesign your code. E.g. use a separate thread. E.g. https://stackoverflow.com/a/1216799/38368

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looping through a large text file and im looking for lines that
I'm trying to populate a dataset with records from a MySql database, then looping
I need to find records in a dataset that have certain values from more
While looping through a Dataset which code snippet should I use, should I go
Having some trouble looping through these arrays , i have 4 properties that identical
This is my problem: I'm reading data from an Excel file on a .NET
I am looping through a dataset for each data row foreach (DataRow DRow in
I'm trying to transfer data from a DataSet into an Excel workbook. Unfortunately, I
Looping through each id retrieve value of objects in 1 dimentional array and 2
When looping through a DataRow and encountering types such as DataRow dr; dr[someString] dr[someInteger]

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.