使用 Win32::ChangeNotify 并等待操作完成 [英] Using Win32::ChangeNotify and waiting for the operation to complete

查看:42
本文介绍了使用 Win32::ChangeNotify 并等待操作完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况:我正在查看一个带有 Win32::ChangeNotify 的文件夹(这里不关心跨平台).该文件夹共享到本地网络.将从另一台计算机在此文件夹中创建一个文件.这个过程需要一些时间.

Situation: I'm watching a folder with Win32::ChangeNotify (don't care about cross-plattform here). The folder is shared to the local network. A file will be created in this folder from another computer. This process will take some time.

问题:在文件仍在写入时触发某些更改的事件.如何等待写操作完成?

Problem: The event that something changed is fired while the file is still being written. How can I wait for the write-opertation to finish?

我的代码如下所示:

my $notify = Win32::ChangeNotify->new($watched_folder, 0, "LAST_WRITE");
if ($notify->wait(5000) == 1) {
    # 1 = The object is signalled
}

推荐答案

您可能想要执行诸如存储和检查事件之间的文件大小之类的操作,或者在检测到新文件后触发不同的观察程序来执行此操作.在文件大小没有改变的可接受期限之后,您可以合理地期望打开文件.

You probably want to do something like store and check the file size in between events and or fire off a different watcher to do this once you detect the new file. After an accepted period where the file size has not changed then you can reasonably expect to open the file.

我以前在 INotify 中采用过这种方法.

I've taken this approach with INotify before.

这篇关于使用 Win32::ChangeNotify 并等待操作完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆