/// <summary> /// Disposes ShellObjectWatcher /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { Stop(); _manager.UnregisterAll(); if (_listenerHandle != IntPtr.Zero) { MessageListenerFilter.Unregister(_listenerHandle, _message); } }
/// <summary> /// Creates the ShellObjectWatcher for the given ShellObject /// </summary> /// <param name="shellObject">The ShellObject to monitor</param> /// <param name="recursive">Whether to listen for changes recursively (for when monitoring a container)</param> public ShellObjectWatcher(ShellObject shellObject, bool recursive) { if (shellObject == null) { throw new ArgumentNullException("shellObject"); } if (_context == null) { _context = new SynchronizationContext(); SynchronizationContext.SetSynchronizationContext(_context); } _shellObject = shellObject; this._recursive = recursive; var result = MessageListenerFilter.Register(OnWindowMessageReceived); _listenerHandle = result.WindowHandle; _message = result.Message; }