Viewing TXT file while app is in runtime.

  • Thread starter Thread starter Marty
  • Start date Start date
M

Marty

Hi,

When writing to a text file from my application using this object:

Dim FileStream As New FileStream(strFileName, FileMode.Append,
FileAccess.Write, FileShare.ReadWrite)

ioFileOUT = New StreamWriter(FileStream)
ioFileOUT.WriteLine(strLine)

If I try to view the txt file (witn notepad) while the program it is
still running, it seem that I see only the file partially.

But when my app is terminated and the ioFileOUT.Close() is called, then
if I open the txt file, I see the whole content.

How can I make it to be able to see the whole content during the runtime?

I don't want to open/close the txt file each time the ioFileOut object
call it, because it is heavy time/CPU consuming for my needs.

Thanks very much.

Marty
 
Marty,
You need to call the "Flush" method of the StreamWriter in order to
flush the data that is in memory to the file.

Example:
ioFileOUT.WriteLine(strLine)
ioFileOUT.Flush()

I wouldn't recommend using the Flush() method after every line of code
you write because you will take a major performance hit if you are
writing large amounts of data to the file.

Regards,
David R. Jenkins
 
Marty,
You need to call the "Flush()" method of the StreamWriter:

ioFileOUT.Flush()

It is not a good idea to always call the Flush() method after each line
of data you write. You will take a major performance hit on your
program if you are writing large amounts of data.
Regards,
David R. Jenkins
 

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

Back
Top