Good day folks,

I searched almost all the topics related to my problem but still no luck of finding some
help. So, I've decided to create a new thread, hoping that someone can shed some light to
my project.

I have a program which reads text files line by line to an array then save a certain part of
that line to some variables

for example:

THE LINE IS: 420510 BRANCH NAME CITY AREA CODE TERMINATOR

THEN THIS WILL BE SAVED IN DIFFERENT VARIABLES LIKE:

PGNUM = 420510
BRNCH = BRANCH NAME AND SO ON..

after which, variables will be saved into a data table and will be displayed in a datagridview..

The problem is, when I am reading/processing a HUGE text file which is 100MB to 1GB in size, there
is this OOM exception thing. Is there any way where I can do this without sacrificing the speed and
performance of my program???

Thanks in advance.

Recommended Answers

I would try to use a paging technique. Google paging DGV or something. Hope it helps.

Jump to Post

Don't read the entire file into memory. Use a StreamReader to read one line at a time.

Jump to Post

All 5 Replies

Here is the part of my code where I stored the text files into an array:

            lines = IO.File.ReadAllLines(txt_Source.Text)
            linecount = IO.File.ReadAllLines(txt_Source.Text).Length

            For page As Integer = pp To linecount - 1
                objArray.Add(lines(page))
            Next

Please HELP!!!!!!!!!!

I would try to use a paging technique. Google paging DGV or something. Hope it helps.

Don't read the entire file into memory. Use a StreamReader to read one line at a time.

If you have that much data, you should probably look at using a database. You can load the datagridview with whatever data you need.

Thanks Guys for your replies. I really appreciate it. :)

And just for the sake of the other members with the same
issue like mine, just follow what ddanbe and jim said.

It works like a charm..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.