Michael
Michael

Reputation: 205

How to live read text file into textbox in C#

How to read live text from a text file into textbox in C#? The file is being updated all the time by another process, and we need to keep displaying the updated text in the textbox.

Any hint will be appreciated,

Thanks,

Upvotes: 2

Views: 1972

Answers (3)

ZombieSheep
ZombieSheep

Reputation: 29953

You should probably think about using a FileSystemWatcher to track changes to the file, and refresh the contents of the textbox whenever you detect a change. You'll need to be careful about concurrency and file locking, though. Probably the safest way to do it would be to read the file into a separate string object, and only update the textbox once you are happy that the read operation succeeded.

Upvotes: 3

Oskar Kjellin
Oskar Kjellin

Reputation: 21880

Use a FileSystemWatcher and catch the event Onchanged. And handle it by reading the file again!

Upvotes: 0

Matthias Meid
Matthias Meid

Reputation: 12513

FileSystemWatcher class might help you doing this:

FileSystemWatcher Class (MSDN)

Cheers Matthias

Upvotes: 0

Related Questions