0

I have a FileSystemWatcher object setup to monitor changes to a log file written by a console app. The notifier filter is set to: watcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.LastAccess; Env: OS: Win 2k8 server.

The console app code that dumps to the stdout that is redirected to the file out.log:

void MySet::Dump() { std::cout << this << endl; fflush(stdout); }

After I run the Dump ( in the immediate window of debugger), the file size remains the same. If I run a "type" command the update seems to happen. Any ideas

c:\temp> dir 5/21/2010 11:11 AM 4,159 out.log

After Dump: (No change )

c:\temp> dir 05/21/2010 11:11 AM 4,159 out.log

Run a "type" command ...

c:\temp>type out.log File now has the new size ... c:\temp> dir 05/21/2010 11:11 AM 4,410 out.log

Why is this behaviour ? Am I missing something here? Thanks in advance.

4

1 に答える 1

0

http://msdn.microsoft.com/en-us/library/ms724290(VS.85).aspx

タイムスタンプは、さまざまな時期にさまざまな理由で更新されます。ファイルのタイムスタンプに関する唯一の保証は、変更を行うハンドルが閉じられたときにファイルの時間が正しく反映されることです。

したがって、閉じるのではなく、フラッシュするだけの場合、最後の書き込みファイル時間の変更を確認しても、トリガーされるとは限りません。

于 2010-05-21T16:25:40.457 に答える