/////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // InitializeSample()
        //
        // Create all sample objects responsible for interacting with UIA and highlighting hyperlinks.
        //
        // Note that this sample app assumes that all required operations succeed. A shipping app
        // would need the appropriate error handling in place.
        //
        /////////////////////////////////////////////////////////////////////////////////////////////////
        void InitializeSample()
        {
            // Initialize the highlighting used to magnify hyperlinks in the browser window.
            _highlight = new Highlight();
            _highlight.Initialize();

            // Initialize the object which will make all the UIA calls on a background MTA thread.
            _linkProcessor = new LinkProcessor();
            _linkProcessor.Initialize(new SampleUIListUpdateDelegate(UpdateListOnUIThread), listViewLinks, _highlight);

            // Initialize the event handler which is called when the UIA tree structure changes in the browser window.
            SampleUIEventHandlerDelegate sampleUIEventHandlerDelegate = new SampleUIEventHandlerDelegate(HandleEventOnUIThread);

            _sampleEventHandler = new SampleEventHandler(this, sampleUIEventHandlerDelegate);
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // Win7UIAClientForm_FormClosed()
        //
        // Uninitialize and release everything created on startup.
        //
        /////////////////////////////////////////////////////////////////////////////////////////////////
        void Win7UIAClientForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (_linkProcessor != null)
            {
                _linkProcessor.Uninitialize();
                _linkProcessor = null;
            }

            if (_highlight != null)
            {
                _highlight.Uninitialize();
                _highlight = null;
            }

            if (_sampleEventHandler != null)
            {
                _sampleEventHandler.Uninitialize();
                _sampleEventHandler = null;
            }

            // Give any background threads created on startup a chance to close down gracefully.
            Thread.Sleep(200);
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // s_DoWork()
        //
        // Static entry point for the background thread on which the calls to UIA will be made.
        //
        /////////////////////////////////////////////////////////////////////////////////////////////////
        private static void s_DoWork(object data)
        {
            LinkProcessor linkProcessor = (LinkProcessor)data;

            linkProcessor.ThreadProc();
        }