File Close Notification
-
Hi Is there a way to get a notification when a file is closed by another program. e.g., I have a txt file in my app in which another program , say notepad, writes something. Is there a way to get to know immediately when that program closes the file. I know i can do it through polling mechanism but i'm looking for a Notification based solution if possible.
"Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"
-
Hi Is there a way to get a notification when a file is closed by another program. e.g., I have a txt file in my app in which another program , say notepad, writes something. Is there a way to get to know immediately when that program closes the file. I know i can do it through polling mechanism but i'm looking for a Notification based solution if possible.
"Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"
You may use the following code if you hav only that file in its directory if there is any other file in the directory a change in any of the file will signal the event. HANDLE hFileChangeHandle = FindFirstChangeNotification("C:\TestDir",TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE); // Wait until a file in the C:\TestDir is changed. if( WAIT_OBJECT_0 == WaitForSingleObject( hFileChangeHandle, INFINITE )) { // Do the action u want to do } RinuRaj
-
You may use the following code if you hav only that file in its directory if there is any other file in the directory a change in any of the file will signal the event. HANDLE hFileChangeHandle = FindFirstChangeNotification("C:\TestDir",TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE); // Wait until a file in the C:\TestDir is changed. if( WAIT_OBJECT_0 == WaitForSingleObject( hFileChangeHandle, INFINITE )) { // Do the action u want to do } RinuRaj
Have you tried this? AFAIK, WaitForSingleObject doesnt work on Change Notification Handles. As per MSDN Documentation it works only on the following object handles. Event Mutex Semaphore Process Thread Anyway... I will give it a try and will let u know the result
"Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"
-
You may use the following code if you hav only that file in its directory if there is any other file in the directory a change in any of the file will signal the event. HANDLE hFileChangeHandle = FindFirstChangeNotification("C:\TestDir",TRUE, FILE_NOTIFY_CHANGE_LAST_WRITE); // Wait until a file in the C:\TestDir is changed. if( WAIT_OBJECT_0 == WaitForSingleObject( hFileChangeHandle, INFINITE )) { // Do the action u want to do } RinuRaj
It works, Thanks But there is a little problem that it fires the notifcation event only if the file has changed. It wont do anything if someone just closes the file. That was what I needed precisely. But anyway.... Thanks a lot.
"Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"
-
It works, Thanks But there is a little problem that it fires the notifcation event only if the file has changed. It wont do anything if someone just closes the file. That was what I needed precisely. But anyway.... Thanks a lot.
"Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"
-
It works, Thanks But there is a little problem that it fires the notifcation event only if the file has changed. It wont do anything if someone just closes the file. That was what I needed precisely. But anyway.... Thanks a lot.
"Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"
-
you may check ReadDirectoryChangesW() use this flag..................FILE_NOTIFY_CHANGE_LAST_ACCESS RinuRaj
This function might work as it is stated but I already said that I dont want to do it through polling mechanism.
"Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"
-
This function might work as it is stated but I already said that I dont want to do it through polling mechanism.
"Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"
Aamir Butt wrote:
...I dont want to do it through polling mechanism.
ReadDirectoryChangesW()
doesn't poll. It uses notification. Keep in mind, though, that Windows NT and Windows 2000 only update the LastAccessTime every hour for performance reasons.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
-
Hi Is there a way to get a notification when a file is closed by another program. e.g., I have a txt file in my app in which another program , say notepad, writes something. Is there a way to get to know immediately when that program closes the file. I know i can do it through polling mechanism but i'm looking for a Notification based solution if possible.
"Some people believe football is a matter of life and death. I'm very disappointed with that attitude. I can assure you it is much, much more important than that. -- Bill Shankly"
See http://www.codeproject.com/file/filechange.asp[^] maybe it is some helpful to you
_**
**_
WhiteSky