简体   繁体   English

FileInfo.length和File.ReadAllText

[英]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. 我正在访问由第三方工具更新的文件,该工具不断从com-port捕获数据并填充该文件。 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). 并且,为了进行检查,我使用FileInfo.Length操作来了解文件的长度,并且我还使用File.ReadAllText(Filename).Contains(SearchText)来检查文件中是否存在必需的关键字(该关键字会不断更新) )。 My Query is whether using FileInfo.Length and File.ReadAllText to the running file affects the update operation done by the third party tool. 我的查询是对正在运行的文件使用FileInfo.LengthFile.ReadAllText是否会影响第三方工具执行的更新操作。 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. 考虑您的存储的IOPS。 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. 只读操作不会影响其他写入操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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