I am trying to create a program that will refresh a *.log file within the program itself (in a RichTextBox), but while the actual application that is writing to that *.log file is open and is utilizing that file as well.
I have tried multiple things with StreamReader, but I can't seem to get anywhere...
Simply, I want to be able to read a *.log file in my Visual Basic 2010 program, but while the actual application that is writing to it is running itself.
How can I do this, as I keep getting the error that another process is utilizing the *.log/text document?
Reading a Text File While a Process is Using It
Page 1 of 14 Replies - 311 Views - Last Post: 01 July 2012 - 08:38 AM
Replies To: Reading a Text File While a Process is Using It
#2
Re: Reading a Text File While a Process is Using It
Posted 30 June 2012 - 10:06 PM
You would do one at a time.
It would happen faster than you think giving the appearance that it was doing them at the same time. Dispose of your streamreader objects properly, and close them and you won't have issues doing both.
This post has been edited by trevster344: 30 June 2012 - 10:06 PM
#3
Re: Reading a Text File While a Process is Using It
Posted 01 July 2012 - 05:40 AM
trevster344, on 30 June 2012 - 10:06 PM, said:
You would do one at a time.
It would happen faster than you think giving the appearance that it was doing them at the same time. Dispose of your streamreader objects properly, and close them and you won't have issues doing both.
I am new to Visual Basic 2010 (as well as this forum), and I don't know if that would work or not. I believe that I just tried disposing of the StreamReader which did not seem to work.
Again, what I am trying to accomplish is making a program that reads a *.log/text file into a RichTextBox, the file being selected by a user through an OpenFileDialog. From there, the user has the option to manually refresh that *.log/text file within the VB 2010 application, but while another process that "owns" the *.log file is writing to it itself.
Ultimately, I cannot stop reading the file as it has to update the RichTextBox from the *.log file every time the user commands it to.
If anyone is curious as well, this "manual refresh" is done through a button click.
#4
Re: Reading a Text File While a Process is Using It
Posted 01 July 2012 - 06:37 AM
Quote
Ultimately, I cannot stop reading the file
You have to. Accept it. You can't keep the file locked up by your reading application and still expect the other application to write to it.
Therefore you have to change your strategy. Use a FileSystemWatcher to observe the events on the file. When the .LastWriteTime changes, you know the other program has written to it, so you can *try* to read it again. Also, this would eliminate the crude click a button to update... your program would update automatically based on a change in the log file.
#5
Re: Reading a Text File While a Process is Using It
Posted 01 July 2012 - 08:38 AM
Personally I'd use a database at this point. Thanks tlhIn'toq for the tips, I forgot about that nifty tool, going to have to get back into the practice of it.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|