c# - Reading from a text file and updating -
i new programming , came across problem , i'm not sure how deal it.
i use line
textbox2.text = system.io.file.readalltext(path);
to read text file , paste contents in textbox2.
now issue text file i'm try read large (couple megabytes) text file. text file contains logs program, new logs added @ bottom of file.
want update textbox2 if text file updated. not sure how in efficient way. 1 way read whole text file again, since text file big, slow process.
i interested in finding out different , faster way handle this. i'm not interested in exact code, hoped find out in direction should , options can consider.
well, 2 obvious things check:
- the size of file (
fileinfo.length
) - the last write time (
filesysteminfo.lastwritetimeutc
)
if keep track of those, should able detect when file has changed - @ least reasonable degree of confidence.
additionally, can use filesystemwatcher
watch changes.
also, might want consider keeping track of you've read - read new data, seeking right place in file.
finally, textbox
may not best user interface huge log file. if structured log file, have structure represented in ui - example, 1 row in table per log entry, potentially filtering options etc.
Comments
Post a Comment