简体   繁体   中英

FileInfo.length and File.ReadAllText

I am accessing a file that is being updated by a third party tool which continuously captures the data from com-port and populates the file. To this file, while data is being populated, I wanted to do few checks to the contents and record the status for my purpose.

And, for doing the checks I use FileInfo.Length operation to know length of the file and I also use File.ReadAllText(Filename).Contains(SearchText) to check if a required keyword is available in the file (which is being updated continuously). My Query is whether using FileInfo.Length and File.ReadAllText to the running file affects the update operation done by the third party tool. Will there be any loss of data to the file being updated by third party tool due to these checking ?

Also, will there be any effect at all like delay in updates to this file etc.?

It's safe to read the file while another process is writing to it. That process will have a write lock and your process will have a read lock.

Also, will there be any effect at all like delay in updates to this file etc.?

It could affect the performance of the writing process. Consider the IOPS of your storage. If you storage is overloaded, any operation you do with it will compete with your writing process, potentially slowing it down.

Short answer, No.

Read Only Operations don't affect other writing operations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM