Can it be slow to write to a very big .txt file?

M

Marty

Hi,

I use a streamwriter object to write in a text files hundreds time per
seconds. When my file get very big, can this process is subject to slow
down my application?

Here is part of my code.
Private ioFileOUT As StreamWriter

'In my constructor
Dim FileOUTStream As New FileStream(strFileName, FileMode.Append, _
FileAccess.Write, FileShare.ReadWrite)
ioFileOUT = New StreamWriter(FileOUTStream)

'In a subroutine
ioFileOUT.WriteLine(strMes)

Thanks :)

Marty
 
M

Marty

I have another question, should I send the writing process in the file
to another thread? Or leave it in the current thread?

Thanks

Marty
 
L

Lucas Tam

Marty said:
I have another question, should I send the writing process in the file
to another thread? Or leave it in the current thread?

If it's a large file, you should move it to a separate thread.

If you're doing a lot of string concatenation, take a look at the
stringbuilder class - it's much faster.
 
M

Marty

Hi Lucas,

I am just writing to the text file to make a backup of my incoming feed.
My file can esaly get up to 400MB. Should I send the process to write
to another thread?

To pass it to the other thread, should I place my string in a collection
(FIFO) that the other thread can pool and write the collection content
to the .txt file?

Thanks

Marty
 
L

Lucas Tam

Marty said:
Hi Lucas,

I am just writing to the text file to make a backup of my incoming feed.
My file can esaly get up to 400MB. Should I send the process to write
to another thread?

If you're writing the file in one chunk (i.e. 400MB at once) you should
move it to a separate thread - this prevents the main GUI thread from being
locked up.

To pass it to the other thread, should I place my string in a collection
(FIFO) that the other thread can pool and write the collection content
to the .txt file?

Sure, you can use the queue object for FIFO. Or you can pass the entire
feed straight to the writing class. However, I like the idea of using a
queue : )
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top