是否可以打开一个文本文件并读取内容,而另一个应用程序正在更新该文件,使其不会导致锁冲突?
Is is possible to open a text file and read the contents while another application is updating the file, in such a way that it does not cause a lock conflict?
我需要从一个应用程序监视日志文件,每次事件发生时由另一个应用程序更新。
I need to monitor a log file from one application which is updated by another application each time an event occurs.
我在检查文件是否正在使用中,但是在所有情况下似乎都不起作用。
I do check if the file is in use before I try to read it, but that does not seem to work in all cases.
谢谢Pieter
推荐答案这取决于第一个应用程序如何打开该文件。
it depends on how the first app open that file.
ie when调用CreateFile API来打开一个文件,有dwShareMode参数告诉api如何打开它(如果这被赋予0,它不能从其他应用程序IIRC访问)。 否则从该文件读取应该没有问题。 如果没有错误,检查是否该文件正在打开只读你可以调用像
i.e when calling CreateFile API to open a file, there is dwShareMode param which tells the api how to open it (if this was given 0, it can't be accessed from other applications IIRC). otherwise there should be no problem with reading from that file. if im not mistaken, to check if that file is being opened read only u can call something like
CreateFile(pchar(fName), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0) ;更多推荐
日志文件监视器
发布评论