// Runs on our Automation thread void UninstallLocationMonitor() { if (_windowLocationWatcher != null) { _windowLocationWatcher.Dispose(); _windowLocationWatcher = null; } }
// Runs on our Automation thread void InstallLocationMonitor(IntPtr hWnd) { if (_windowLocationWatcher != null) { _windowLocationWatcher.Dispose(); } _windowLocationWatcher = new WindowLocationWatcher(hWnd, _syncContextAuto); _windowLocationWatcher.LocationChanged += _windowLocationWatcher_LocationChanged; }
// Runs on our Automation thread void UninstallLocationMonitor() { WindowLocationWatcher tempWatcher = Interlocked.Exchange(ref _windowLocationWatcher, null); if (tempWatcher != null) { _syncContextMain.Post(disp => ((IDisposable)disp).Dispose(), tempWatcher); } }
// Runs on the main thread public void Dispose() { Debug.Assert(Thread.CurrentThread.ManagedThreadId == 1); Logger.WindowWatcher.Verbose("FormulaEdit Dispose Begin"); _windowWatcher.FormulaBarWindowChanged -= _windowWatcher_FormulaBarWindowChanged; _windowWatcher.InCellEditWindowChanged -= _windowWatcher_InCellEditWindowChanged; // Can't call UninstallLocationMonitor - we might be shutting down on the main thread, and don't want to post WindowLocationWatcher tempWatcher = Interlocked.Exchange(ref _windowLocationWatcher, null); if (tempWatcher != null) { tempWatcher.Dispose(); } Logger.WindowWatcher.Verbose("FormulaEdit Dispose End"); }
// Runs on our Automation thread void InstallLocationMonitor(IntPtr hWnd) { UninstallLocationMonitor(); _windowLocationWatcher = new WindowLocationWatcher(hWnd, _syncContextAuto, _syncContextMain); _windowLocationWatcher.LocationChanged += _windowLocationWatcher_LocationChanged; }