正在使用VBA监视文件 [英] VBA watch file in use
问题描述
我正在寻找某种东西(Win API调用或其他东西),以便在文件变为可编辑状态(即不再使用)时通知我.我应该设置一个计时器来检查文件是否间隔一定时间或是否存在在文件上设置监视的好方法吗?
I"m looking for something (Win API calls or whatever) to notify me when a file becomes available for editing (i.e. no longer in use). Should I set up a timer to check the files on some interval or is there a good way to set up a watch on the file?
推荐答案
FileSystemWatcher没有帮助,Win32 FindFirstChangeNotification也没有帮助:当有人释放文件句柄时,它们不会告诉您.
FileSystemWatcher doesn't help, nor does the Win32 FindFirstChangeNotification: they won't tell you when someone releases a file handle.
您最好的方法是定期尝试以所需的访问权限打开文件,以处理所有错误.
Your best way is to periodically attempt to open the file with the access you want, handling any errors.
即使您收到文件可用的通知,也不能保证您随后尝试打开该文件时仍然可用.
Even if you were notified that a file was available, that won't guarantee that it will still be available when you subsequently try to open it.
这篇关于正在使用VBA监视文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!