protected override void Dispose(bool disposing)
 {
     if (!disposedValue)
     {
         if (disposing)
         {
             if (this.IsHooked)
             {
                 IUIAutomation uia = this.IUIAutomation;
                 if (uia != null)
                 {
                     uia.RemoveStructureChangedEventHandler(this.Element, this);
                 }
             }
         }
     }
     base.Dispose(disposing);
 }
Esempio n. 2
0
        /////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // RemoveSampleEventHandler()
        //
        // Perform all cleanup of objects that we initialized on startup in the background thread.
        //
        // Runs on the background thread.
        //
        /////////////////////////////////////////////////////////////////////////////////////////////////
        void RemoveSampleEventHandler()
        {
            // If we successfully added an event handler earlier, remove it now. The
            // handler must be removed on the same thread on which it was added.
            if (_fAddedEventHandler)
            {
                // Depending on the timing of events generated around the time we remove
                // the event handler, an event can arrive at the handler after a successful
                // call to remove the event handler. So set the flag here to prevent our
                // event handler from taking any more action if futher calls to our event
                // handler are made.
                _fAddedEventHandler = false;

                try
                {
                    _automation.RemoveStructureChangedEventHandler(_elementBrowser, this);
                }
                catch
                {
                    // An exception can be thrown here if the browser window has already been closed.
                }
            }
        }