예제 #1
0
 public void StopParsing()
 {
     try
     {
         //UnAdvice and clean up
         if ((m_WBConnectionPoint != null) && (m_dwCookie > 0))
         {
             m_WBConnectionPoint.Unadvise(m_dwCookie);
         }
         if (m_WBOleObject != null)
         {
             m_WBOleObject.Close((uint)OLEDOVERB.OLECLOSE_NOSAVE);
             m_WBOleObject.SetClientSite(null);
         }
         if (m_pMSHTML != null)
         {
             Marshal.ReleaseComObject(m_pMSHTML);
             m_pMSHTML = null;
         }
         if (m_WBConnectionPoint != null)
         {
             Marshal.ReleaseComObject(m_WBConnectionPoint);
             m_WBConnectionPoint = null;
         }
         if (m_WBOleControl != null)
         {
             Marshal.ReleaseComObject(m_WBOleControl);
             m_WBOleControl = null;
         }
         if (m_WBOleObject != null)
         {
             Marshal.ReleaseComObject(m_WBOleObject);
             m_WBOleObject = null;
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #2
0
        public void CloseDocument()
        {
            try
            {
                container.releaseWndProc();
                container.Resize -= new EventHandler(this.Container_Resize);

                if (m_document == null)
                {
                    return;
                }

                try
                {
                    //this may raise an exception, however it does work and must
                    //be called
                    if (view != null)
                    {
                        view.Show(-1);
                        view.UIActivate(-1);
                        view.SetInPlaceSite(null);
                        view.CloseView(0);
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine("CloseView raised exception: " + e.Message);
                }

                try
                {
                    //this could raise an exception too, but it must be called
                    m_document.Close((int)tagOLECLOSE.OLECLOSE_NOSAVE);
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Close document raised exception: " + e.Message);
                }

                m_document.SetClientSite(null);

                win32.OleLockRunning(m_document, false, false);

                if (this.iAdviseCookie != 0)
                {
                    m_document.Unadvise(this.iAdviseCookie);
                }

                if (this.iEventsCookie != 0)
                {
                    m_document.Unadvise(this.iEventsCookie);
                }

                if (this.iPropertyNotifyCookie != 0)
                {
                    m_document.Unadvise(this.iPropertyNotifyCookie);
                }

                if (container.changeCookie != 0)
                {
                    ((IMarkupContainer2)m_document).UnRegisterForDirtyRange(container.changeCookie);
                    container.changeCookie = 0;
                }

                //release COM objects
                int RefCount = 0;

                if (m_document != null)
                {
                    do
                    {
                        RefCount = Marshal.ReleaseComObject(m_document);
                    } while (RefCount > 0);
                }

                if (view != null)
                {
                    do
                    {
                        RefCount = Marshal.ReleaseComObject(view);
                    } while (RefCount > 0);
                }

                if (activeObject != null)
                {
                    do
                    {
                        RefCount = Marshal.ReleaseComObject(activeObject);
                    } while (RefCount > 0);
                }

                m_document         = null;
                view               = null;
                activeObject       = null;
                container.mHtmlDoc = null;
                container.mDocHTML = null;
            }
            catch (Exception e)
            {
                Debug.WriteLine("CloseDocument raised exception: " + e.Message);
            }
        }