[dba-VB] Unhooking events while they are running

Stuart McLachlan stuart at lexacorp.com.pg
Tue Nov 1 16:33:51 CDT 2011


To quote MS: A hook is a point in the system message-handling mechanism where an 
application can install a subroutine to monitor the message traffic in the system and process 
certain types of messages before they reach the target window procedure. 

Is that what you are actually doing  i.e. "intercepting"  and acting on messages intended for 
another target ?   

Or are you just using a FileSystemWatcher, which is basically a wrapper for 
WaitForSingleObject in Kernel32.DLL, to monitor changes?

If the latter, I'd say you solution is quite adequate.



On 1 Nov 2011 at 15:44, jwcolby wrote:

> I am using the directory watcher class.  When the parent class to
> start, it hooks the events and when it is told to stop it unhooks the
> events.
> 
> My question is simply that events are asynchronous and as such could
> occur at the same instant that the parent class is being told to stop.
>  I use a boolean evFileDeletedIsRunning flag which the event sets as
> the first line inside of that event and clears as the last line of the
> event.  I then check this flag before unhooking the event.
> 
> Is this adequate protection?  What happens if an event is unhooked
> while the event sink is running? 
>   Is it a page fault or something less catastrophic?
> 
> -- 
> John W. Colby
> Colby Consulting
> 
> Reality is what refuses to go away
> when you do not believe in it
> _______________________________________________
> dba-VB mailing list
> dba-VB at databaseadvisors.com
> http://databaseadvisors.com/mailman/listinfo/dba-vb
> http://www.databaseadvisors.com
> 
> 






More information about the dba-VB mailing list