Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,063 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,582 people online right now. Registration is fast and FREE... Join Now!




StreamReader takes long time to read csv file

 
Reply to this topicStart new topic

StreamReader takes long time to read csv file

ms3009
8 Apr, 2008 - 10:18 PM
Post #1

New D.I.C Head
*

Joined: 8 Apr, 2008
Posts: 1

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...

csharp

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.gif


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

This post has been edited by Martyr2: 9 Apr, 2008 - 08:20 AM
User is offlineProfile CardPM
+Quote Post

zakary
RE: StreamReader Takes Long Time To Read Csv File
9 Apr, 2008 - 05:20 AM
Post #2

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 404



Thanked: 6 times
Dream Kudos: 175
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: StreamReader Takes Long Time To Read Csv File
9 Apr, 2008 - 08:25 AM
Post #3

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,198



Thanked: 213 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
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! smile.gif

This post has been edited by Martyr2: 9 Apr, 2008 - 08:25 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 06:38PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month