2 Replies - 14350 Views - Last Post: 09 April 2008 - 09:25 AM Rate Topic: -----

#1 ms3009  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 08-April 08

StreamReader takes long time to read csv file

Posted 08 April 2008 - 11:18 PM

Hi Every one,

I am using StreamReader to read my csv file.
My csv file contains very huge data, around 17200 line...

my probelm is, when i execute my application and try to read csv file, then my application screen becomes blank (Consumes memory).

I am using following code to read file...

using (StreamReader sr = new StreamReader(fileStream))  
//fileStream is my FileStream object...
// which i have initialized as
//fileStream = new FileStream(CSVFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
{
      String temp;
      while ((temp = sr.ReadLine()) != null)
      {
         if (l_strCSVData.Trim().ToString().Equals(""))
               l_strCSVData = temp;
         else
               l_strCSVData = l_strCSVData + '\n' + temp;
       }
}


*edit: Please use code tags in the future, thanks! :code:


is there any way to make this reading process fast, so that my screen wont get blank???

This post has been edited by Martyr2: 09 April 2008 - 09:20 AM


Is This A Good Question/Topic? 1
  • +

Replies To: StreamReader takes long time to read csv file

#2 zakary  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 427
  • Joined: 15-February 05

Re: StreamReader takes long time to read csv file

Posted 09 April 2008 - 06:20 AM

No it is only as fast as the Computers processor will allow, what you can do is put that in a separate thread and maybe use a progress bar to show the user that your application is doing something.
Was This Post Helpful? 1
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,127
  • Joined: 18-April 07

Re: StreamReader takes long time to read csv file

Posted 09 April 2008 - 09:25 AM

zakary's advice is bang on... what you are seeing is not a consumption of memory, but consuming up your processors time (it doesn't have time to repaint the screen, it is processing your file). The remedy is exactly what zakary said, use a separate thread which will divide the CPU's time (of if you have a multicore, multiple processors they will process it) between painting the screen and reading the file. This will also allow you the ability to setup a progress bar to display the progress of the file reading to the user while they do other things.

For more information on threading, try a site like the one listed below which will show you how C# threading works and gives examples...

Threading in C# - Free E-book

Enjoy! :)

This post has been edited by Martyr2: 09 April 2008 - 09:25 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1