/// <summary> /// If you want to immediately uninstall a hook, the only way is to dispose it. A disposed /// hook is guaranteed to never invoke your handler again but may still consume /// memory even for process life-time! /// </summary> /// <remarks> /// As we are living in a manged world, you don't have to dispose a hook because the next /// garbage collection will do it for you, assuming that your code does not reference it /// anymore. But there are times when you want to uninstall it excplicitly, with no delay. /// If you dispose a disposed or not installed hook, nothing will happen! /// </remarks> public void Dispose() { lock (m_ThreadSafe) { if (IntPtr.Zero == m_Handle) { return; } NativeAPI.LhUninstallHook(m_Handle); Marshal.FreeCoTaskMem(m_Handle); m_Handle = IntPtr.Zero; m_Callback = null; m_HookProc = null; m_SelfHandle.Free(); } }